Elasticsearch更像是使用like_text的查询

时间:2015-04-16 19:28:11

标签: elasticsearch

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

这是我的索引创建:

curl -XPUT 'http://127.0.0.1:9200/food/' -d 
'{
  "mappings": {
    "fruit": {
      "properties": {
        "term": {
          "type": "string",
          "term_vector": "yes"
        }
      }
    }
  }
}'

以下是该索引中的一段数据示例:

{
  "_index": "food",
  "_type": "fruit",
  "_id": "2",
  "_score": 1,
  "_source": {
    "term": "yellow",
    "property_ids": [
      1
    ],
    "id": 2
  }
}

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

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

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

{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}%

如果我只对“黄色”执行标准通配符查询,我会得到该结果。我错过了什么?

1 个答案:

答案 0 :(得分:7)

默认情况下,min_doc_freq为5(check doc)因此,您的查询无效,因为您的索引不包含至少5个term属性保留{{1}的文档}}。因此,在查询中将yellow设置为1,它应该可以正常工作。例如:

min_doc_freq