Elasticsearch更像是使用like_text的查询

Dav*_*and 3 elasticsearch

我对使用更像这个查询感到沮丧.

这是我的索引创建:

curl -XPUT 'http://127.0.0.1:9200/food/' -d 
'{
  "mappings": {
    "fruit": {
      "properties": {
        "term": {
          "type": "string",
          "term_vector": "yes"
        }
      }
    }
  }
}'
Run Code Online (Sandbox Code Playgroud)

这是该索引中的一个示例数据:

{
  "_index": "food",
  "_type": "fruit",
  "_id": "2",
  "_score": 1,
  "_source": {
    "term": "yellow",
    "property_ids": [
      1
    ],
    "id": 2
  }
}
Run Code Online (Sandbox Code Playgroud)

最后这里更像是我用来对它尝试返回数据的查询:

curl -XGET 'http://127.0.0.1:9200/food/_search' -d '{
  "query": {
    "more_like_this": {
      "fields": [
        "term"
      ],
      "like_text": "yellow",
      "min_term_freq": 1,
      "max_query_terms": 12
    }
  }
}
'
Run Code Online (Sandbox Code Playgroud)

问题是,当我进行此搜索时,我得不到任何结果:

{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}%
Run Code Online (Sandbox Code Playgroud)

如果我只为"黄色"执行标准通配符查询,我会得到该结果.我错过了什么?

mol*_*are 7

默认情况下min_doc_freq为5(检查文档),因此,您的查询无效,因为您的索引不包含至少5个term属性所在的文档yellow.因此,min_doc_freq在您的查询中设置为1,它应该工作.例:

{
    "query": {
        "more_like_this": {
            "fields": [
                "term"
             ],
             "like_text": "yellow",
             "min_term_freq": 1,
             "min_doc_freq": 1,
             "max_query_terms": 12
         }
    }
}
Run Code Online (Sandbox Code Playgroud)