zoukankan      html  css  js  c++  java
  • 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就可以正常使用得到查询结果为不分词的了。

     
     
  • 相关阅读:
    五种排序算法
    call,apply,bind实现
    js面试题
    Date日期方法
    操作符
    var、let和const
    script标签属性
    HbuilderX如何让项目运行到微信开发者工具
    vite搭建vue3项目
    瀑布流实例及懒加载(echo.js)
  • 原文地址:https://www.cnblogs.com/crystaltu/p/7200120.html
Copyright © 2011-2022 走看看