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

来源:互联网 发布:sql语句查询所有库存 编辑:程序博客网 时间:2024/05/21 17:49

     最近在使用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就可以正常使用了。

0 0
原创粉丝点击