Elasticsearch更多类似的没有结果 [英] Elasticsearch More Like this no result

查看:36
本文介绍了Elasticsearch更多类似的没有结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图弄清More like this query(ES 2.X)的工作原理.我用术语向量创建了以下索引.

I'm trying to figure out how does More like this query works (ES 2.X). I have created the following index with term vector.

PUT /test_index
{
   "settings": {
      "number_of_shards": 1,
      "number_of_replicas": 0
   },
   "mappings": {
      "doc": {
         "properties": {
            "text": {
               "type": "string",
               "term_vector": "yes"
            }
         }
      }
   }
}

PUT /test_index/doc/1
{
    "text": ["Hello","World"]
}

PUT /test_index/doc/2
{
    "text": ["This","is","me"]
}

PUT /test_index/doc/3
{
    "text": ["Hello","World"]
}

PUT /test_index/doc/4
{
    "text": ["Hello","World","World"]
}

为什么以下查询没有返回结果?在第二个查询中,我希望至少检索具有与doc 1相同值的doc 3.

Why do the following queries returns no result? With the second query I expected to retrieve at least doc 3, which has the same values of doc 1.

POST /test_index/doc/_search
{
   "query": {
      "more_like_this": {
         "like": "Hello",
         "min_term_freq": 1
      }
   }
}

POST /test_index/doc/_search
{
   "query": {
      "more_like_this": {
         "fields": [
            "text"
         ],
         "like": [
            {
               "_index": "test_index",
               "_type": "doc",
               "_id": "1"
            }
         ]
      }
   }
}

推荐答案

默认情况下 min_doc_freq 是5,因此您的查询无法正常工作,因为您的索引中至少包含5个文档,其> term 属性保持黄色.因此,在查询中将 min_doc_freq 设置为1,它应该可以工作.

By default min_doc_freq is 5, So your query is not working because your index doesn't contain at least 5 documents whose term property holds yellow. So, set min_doc_freq to 1 in your query and it should work.

{
    "query": {
        "more_like_this": {
            "like": "Hello",
            "min_term_freq": 1,
            "min_doc_freq": 1
        }
    }
}

这篇关于Elasticsearch更多类似的没有结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆