简体   繁体   English

ElasticSearch-模糊搜索Java API结果不正确

[英]ElasticSearch - fuzzy search java api results are not proper

I have indexed sample documents in elasticsearch and trying to search using fuzzy query. 我在elasticsearch中索引了示例文档,并尝试使用模糊查询进行搜索。 But am not getting any results when am search by using Java fuzzy query api. 但是使用Java模糊查询api搜索时没有得到任何结果。

Please find my below mapping script : 请在下面找到我的映射脚本:

PUT productcatalog
 {
    "settings": {
        "analysis": {
            "analyzer": {
                "attr_analyzer": {
                    "type": "custom",
                    "tokenizer": "letter",
                    "char_filter": [
                        "html_strip"
                    ],
                    "filter": ["lowercase", "asciifolding", "stemmer_minimal_english"]
                }
            },
            "filter" : {
                "stemmer_minimal_english" : {
                    "type" : "stemmer",
                    "name" : "minimal_english"
                }
            }
        }
    },
    "mappings": {
        "doc": {
            "properties": {
                "values": {
                    "type": "text",
                    "analyzer": "attr_analyzer"
                },
                "catalog_type": {
                    "type": "text"
                },
                "catalog_id":{
                    "type": "long"
                }
            }
        }
    }
}

Please find my sample data. 请找到我的样本数据。

PUT productcatalog/doc/1
{
    "catalog_id" : "343",
    "catalog_type" : "series",
    "values" : "Activa Rooftop, valves, VG3000, VG3000FS, butterfly, ball"
}


PUT productcatalog/doc/2
{
    "catalog_id" : "12717",
    "catalog_type" : "product",
    "values" : "Activa Rooftop, valves"
}

Please find my search script : 请找到我的搜索脚本:

GET productcatalog/_search
{
    "query": {
        "match" : {
            "values" : {
                "query" : " activa rooftop VG3000",
                "operator" : "and",
                 "boost": 1.0,
                "fuzziness": 2,
                "prefix_length": 0,
                "max_expansions": 100


            }
        }
    }
}

Am getting the below results for the above query : 我正在获取上述查询的以下结果:

{
  "took": 239,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.970927,
    "hits": [
      {
        "_index": "productcatalog",
        "_type": "doc",
        "_id": "1",
        "_score": 0.970927,
        "_source": {
          "catalog_id": "343",
          "catalog_type": "series",
          "values": "Activa Rooftop, valves, VG3000, VG3000FS, butterfly, ball"
        }
      }
    ]
  }
}

But if i use the below Java API for the same fuzzy search am not getting any results out of it. 但是,如果我对相同的模糊搜索使用以下Java API,则不会得到任何结果。

Please find my below Java API query for fuzzy search : 请找到我下面的Java API查询进行模糊搜索:

QueryBuilder qb = QueryBuilders.boolQuery()
               .must(QueryBuilders.fuzzyQuery("values", keyword).boost(1.0f).prefixLength(0).maxExpansions(100));

Update 1 更新1

I have tried with the below query 我已经尝试过以下查询

QueryBuilder qb = QueryBuilders.matchQuery(QueryBuilders.fuzzyQuery("values", keyword).boost(1.0f).prefixLength(0).maxExpansions(100));

But am not able to pass QueryBuilders inside matchQuery . 但是无法在QueryBuilders内部传递matchQuery Am getting this suggestion while am writing this query The method matchQuery(String, Object) in the type QueryBuilders is not applicable for the arguments (FuzzyQueryBuilder) 在编写此查询时得到了这个建议The method matchQuery(String, Object) in the type QueryBuilders is not applicable for the arguments (FuzzyQueryBuilder)

The mentioned java query is not a match query. 提到的Java查询不是match查询。 It's a must query. 这是must查询的。 you should use matchQuery instead of boolQuery().must(QueryBuilders.fuzzyQuery()) 您应该使用matchQuery而不是boolQuery().must(QueryBuilders.fuzzyQuery())

Update 1 : 更新1

fuzzy query is a term query while match query is a full text query. 模糊查询术语查询,而匹配查询全文查询。

Also don't forget that in match query the default Operator is or operator which you should change it to and like your dsl query. 同样不要忘记,在匹配查询中,默认的Operator是or ,您应该将其更改为and就像dsl查询一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM