Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch More Like this no result

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

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"
            }
         ]
      }
   }
}
like image 891
betto86 Avatar asked Oct 25 '16 09:10

betto86


Video Answer


1 Answers

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
        }
    }
}
like image 98
vinod_vh Avatar answered Oct 24 '22 15:10

vinod_vh