elasticsearch,elastic-stack,fuzzy-search,Java,elasticsearch,Elastic Stack,Fuzzy Search" /> elasticsearch,elastic-stack,fuzzy-search,Java,elasticsearch,Elastic Stack,Fuzzy Search" />

ElasticSearch-fuzzyQuery Java API响应与matchQuery几乎相同

ElasticSearch-fuzzyQuery Java API响应与matchQuery几乎相同,java,elasticsearch,elastic-stack,fuzzy-search,Java,elasticsearch,Elastic Stack,Fuzzy Search,我试图使用matchQuery和fuzzyQuery从弹性搜索中获取文档,但是我得到的两个API的响应计数相同 例如: 场景1(使用matchQuery) Am使用matchQuery搜索阀门,并使用下面的matchQueryAPI获取36的计数 QueryBuilder qb = QueryBuilders.boolQuery() .must(QueryBuilders.matchQuery("catalog_value", "valve"))

我试图使用
matchQuery
fuzzyQuery
从弹性搜索中获取文档,但是我得到的两个API的响应计数相同

例如:

场景1(使用matchQuery)

Am使用matchQuery搜索阀门,并使用下面的
matchQuery
API获取
36
的计数

QueryBuilder qb = QueryBuilders.boolQuery()
                        .must(QueryBuilders.matchQuery("catalog_value", "valve"))
                       .filter(QueryBuilders.termQuery("locale", "en_US" ));
QueryBuilder qb = QueryBuilders.boolQuery()
                      .must(QueryBuilders.fuzzyQuery("catalog_value", "valve"))
                      .filter(QueryBuilders.termQuery("locale", "en_US"));
如果我搜索
阀门
也只得到
14
计数

场景2(使用fuzzyQuery)

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

QueryBuilder qb = QueryBuilders.boolQuery()
                        .must(QueryBuilders.matchQuery("catalog_value", "valve"))
                       .filter(QueryBuilders.termQuery("locale", "en_US" ));
QueryBuilder qb = QueryBuilders.boolQuery()
                      .must(QueryBuilders.fuzzyQuery("catalog_value", "valve"))
                      .filter(QueryBuilders.termQuery("locale", "en_US"));
如果我搜索
阀门
也只得到
14
计数。实际上,如果我们使用fuzzyQuery,我希望
valve
valves
都应该给出相同的计数

任何人都知道FuzzyQueryAPI

Am使用ElasticSearch 6.2.3版本

阀门匹配的示例文档

    {  
    "_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"
}
QueryBuilder qb1 = QueryBuilders.boolQuery()
                    .must(QueryBuilders.fuzzyQuery("product_attr_value", keyword).boost(1.0f).prefixLength(0).fuzziness(Fuzziness.AUTO).transpositions(true));
请查找我的映射详细信息:

        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"
         }

        }
       }
      }
}
更新

我已经使用以下场景进行了测试,得到了以下计数

valve    --> 17
valves   --> 7
valvess  --> 7
valvesss --> 8

val      --> 17
valv     --> 17
更新2

使用下面修改的查询并获得下面的结果计数

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


valve    --> 17
valves   --> 7
valvess  --> 8
valvesss --> 0

val      --> 17
valv     --> 17 
更新3

使用下面的模糊查询,我无法获得
的正确结果计数

    {  
    "_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"
}
QueryBuilder qb1 = QueryBuilders.boolQuery()
                    .must(QueryBuilders.fuzzyQuery("product_attr_value", keyword).boost(1.0f).prefixLength(0).fuzziness(Fuzziness.AUTO).transpositions(true));
对于,
valve
valves
搜索,我总共得到了10个结果计数(我将计数限制为10个),并且没有一个文档匹配在一起

例如,下面是我为
valve
valves
搜索获得的ID

"hits":[  
     {  
        "_index":"product_offering",
        "_type":"doc",
        "_id":"kE89_2QBfp1CuLwJxs-W",
        "_score":3.0630755,
        "_source":{  
           "product_status":"ACT",
           "@timestamp":"2018-08-03T10:03:12.194Z",
           "product_code":"M9000-560",
           "std_delivery_time":0,
           "product_attr_type":null,
           "label":"long_description",
           "product_attr_value":"Ball Valve Linkage Kit for applying M9203 and M9208 Series Actuators to VG1000 Series Valves",
           "is_product_visible":1,
           "product_name":"product17167",
           "product_group":"single",
           "product_id":17194,
           "@version":"1",
           "catalog_id":264,
           "locale":"en_US",
           "expiration_date":null,
           "product_type":"accessory",
           "min_order_quantity":1,
           "product_attr_name":"product17167_long_description"
        }
     },
阀门:

17194
219575
219574
280638
282288
298177
295626
4112
219069
219381
阀门的样本响应
搜索

"hits":[  
     {  
        "_index":"product_offering",
        "_type":"doc",
        "_id":"kE89_2QBfp1CuLwJxs-W",
        "_score":3.0630755,
        "_source":{  
           "product_status":"ACT",
           "@timestamp":"2018-08-03T10:03:12.194Z",
           "product_code":"M9000-560",
           "std_delivery_time":0,
           "product_attr_type":null,
           "label":"long_description",
           "product_attr_value":"Ball Valve Linkage Kit for applying M9203 and M9208 Series Actuators to VG1000 Series Valves",
           "is_product_visible":1,
           "product_name":"product17167",
           "product_group":"single",
           "product_id":17194,
           "@version":"1",
           "catalog_id":264,
           "locale":"en_US",
           "expiration_date":null,
           "product_type":"accessory",
           "min_order_quantity":1,
           "product_attr_name":"product17167_long_description"
        }
     },
阀门:

15680
15572
15599
15615
15674
15650
15526
15543
6869
6868
阀门
搜索的样本响应(当am搜索
阀门
时不可用)


您使用的是哪个版本的ElasticSearch?我很想看到一个文档在使用模糊性查询
阀门时没有返回,即使它应该返回。@Nick-Am使用的是ElasticSearch 6.2.3版本。@Val-Am不确定。我是否正确地生成了模糊查询。您能显示一个匹配的示例文档吗?