Elasticsearch 全字段搜索_all,query_string查询,不进行分词

最近在使用ELasitcsearch的时候,需要用到关键字搜索,因为是全字段搜索,就需要使用_all字段的query_string进行搜索。

但是在使用的时候,遇到问题了。我们的业务并不需要分词,我在各个字段也设置了,not_analyzed。但是在使用query_string对_all字段进行查询的时候,

发现结果还是分词的。最后在官网找到这么一段话:

Remember that the _all field is just an analyzed string field. It uses the default analyzer to analyze its values, regardless of which analyzer has been set on the fields where the values originate. And like any string field, you can configure which analyzer the _all field should use:

PUT /my_index/my_type/_mapping
{
"my_type": {
"_all": { "analyzer": "whitespace" }
}
}

 

就是说,我们在字段中的分词设置并不管用,如果不需要分词,只能重新设置。也就是为_all指定分词器。这里,我指定了通过空格去进行分词。

终于,通过query_string就可以正常使用得到查询结果为不分词的了。

 
 
posted @ 2017-07-18 13:50  Nullnullisnull  阅读(13581)  评论(0编辑  收藏  举报