ElasticSearch-FuzzyQuery Java API无法正确给出结果

时间:2018-08-02 18:21:44

标签: java elasticsearch elastic-stack fuzzy-search

我正尝试使用fuzzyQuery从弹性搜索中获取文档,但未获得正确的响应。

例如:

Am使用FuzzyQuery搜索阀门,并使用下面的17 API获取fuzzyQuery的计数

 QueryBuilder qb1 = QueryBuilders.boolQuery()
            .must(QueryBuilders.fuzzyQuery("catalog_value", "valve").boost(1.0f).prefixLength(0).fuzziness(Fuzziness.ONE).transpositions(true))
            .filter(QueryBuilders.termQuery("locale", "en_US"));


valve    --> 17

如果搜索valves,则获得8的计数,而下面的fuzzyQuery

 QueryBuilder qb1 = QueryBuilders.boolQuery()
            .must(QueryBuilders.fuzzyQuery("catalog_value", "valves").boost(1.0f).prefixLength(0).fuzziness(Fuzziness.ONE).transpositions(true))
            .filter(QueryBuilders.termQuery("locale", "en_US"));

valves   --> 8

但是我希望valvevalves都应该返回相同的结果计数,如果我使用fuzzyQuery

我使用的是ElasticSearch 6.2.3版本。

匹配valves的示例文档。

    {  
    "_index":"catalog",
    "_type":"doc",
    "_id":"517yxmQB1-MO2Tblt7C3",
    "_score":1.0,
    "_source":{  
       "catalog_name":"family451",
       "catalog_value":"These control valves range with actuation choices featuring.",
       "catalog_id":41065,
       "@version":"1",
       "locale":"en_US",
       "@timestamp":"2018-07-23T11:42:29.751Z"
}

请找到我的地图详细信息:

        PUT catalog
    {
      "settings": {
        "analysis": {
        "analyzer": {
           "value_analyzer": {
           "type": "custom",
            "tokenizer": "whitespace",
           "char_filter": [
            "html_strip"
           ],
           "filter": ["lowercase", "asciifolding"]
         }
       }
     }
    },
    "mappings": {
      "doc": {
        "properties": {
          "catalog_value": {
            "type": "text",
            "analyzer": "value_analyzer"
          },
          "catalog_id": {
            "type": "long"
          },
         "catalog_name":{
         "type":"keyword"
         },
         "locale":{
         "type":"keyword"
         }

        }
       }
      }
}

0 个答案:

没有答案