Elasticsearch looks more like this query using like_text

I have some frustration using a query more similar to this one.

Here is my index creation:

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

      

And here's a sample of the data in that index:

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

      

Finally, here's more like this query that I'm using against it to try and return data:

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

      

The problem is when I do this search I don't get any results:

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

      

If I make a standard group request for "yellow" I get this result back. What am I missing?

+3


source to share


1 answer


The default min_doc_freq

is 5 ( validate document ), so your query doesn't work because your index does not contain at least 5 documents whose property term

contains yellow

. So, set min_doc_freq

to 1 in your query and it should work. Example:



{
    "query": {
        "more_like_this": {
            "fields": [
                "term"
             ],
             "like_text": "yellow",
             "min_term_freq": 1,
             "min_doc_freq": 1,
             "max_query_terms": 12
         }
    }
}

      

+7


source







All Articles