簡體   English   中英

ElasticSearch-模糊搜索Java API結果不正確

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

我在elasticsearch中索引了示例文檔,並嘗試使用模糊查詢進行搜索。 但是使用Java模糊查詢api搜索時沒有得到任何結果。

請在下面找到我的映射腳本:

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

請找到我的樣本數據。

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

請找到我的搜索腳本:

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


            }
        }
    }
}

我正在獲取上述查詢的以下結果:

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

但是,如果我對相同的模糊搜索使用以下Java API,則不會得到任何結果。

請找到我下面的Java API查詢進行模糊搜索:

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

更新1

我已經嘗試過以下查詢

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

但是無法在QueryBuilders內部傳遞matchQuery 在編寫此查詢時得到了這個建議The method matchQuery(String, Object) in the type QueryBuilders is not applicable for the arguments (FuzzyQueryBuilder)

提到的Java查詢不是match查詢。 這是must查詢的。 您應該使用matchQuery而不是boolQuery().must(QueryBuilders.fuzzyQuery())

更新1

模糊查詢術語查詢,而匹配查詢全文查詢。

同樣不要忘記,在匹配查詢中,默認的Operator是or ,您應該將其更改為and就像dsl查詢一樣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM