elasticsearch中遇到的一些问题以及解决方式

(1)submitDate(08-MAY-2013)字段支持范围搜索的解决方式:
"submitDate": {    
    "type": "Date",
    "format": "dd-MMM-yyyy",
    "locale": "US"
}
说明:首先将字段类型(type)修改为Date类型(elasticsearch默认是string),然后添加("locale":"US")用来识别日期格式中带有英文缩写的数据。
(2)elasticsearch中的analyzer:
数据录入elasticsearch之前,analyzer会对数据进行分词(elasticsearch默认会自动分词,将一句话分为多个单词,并且将单词的大写字母变为小写),这样会影响对字段的精准搜索。
(3)字段精准搜索的解决方式分为两种:
第一种:改变elasticsearch的默认搜索方式:
            "submitAddress": {
                "type": "string",
        "index": "not_analyzed"
            },
第二种方式:搜索的时候可以用双引号引起要搜索的内容。

5)java api录入数据和搜索数据的基本用法(代码):
建立客户端的方式:

// establish the client
Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name","genbank").build();
@SuppressWarnings("resource")
Client client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress("10.0.26.1", 9300));

录入数据和搜索数据的一些代码:
录入:
client.prepareIndex("test","seqs","seqs_"+i).setSource(jsonValue).execute().actionGet();
读取数据:
QueryBuilder queryBuilder = QueryBuilders.boolQuery().must(QueryBuilders.termQuery("comment", "sequence"));
//SearchResponse searchResponse = client.prepareSearch("genbank").setTypes("seq").setQuery(queryBuilder).execute()
.actionGet();
//hits result
SearchHits hits = searchResponse.getHits();

































  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值