(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();