I'm having some frustration using the more like this query.
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 is a sample piece of data in that index:
{
"_index": "food",
"_type": "fruit",
"_id": "2",
"_score": 1,
"_source": {
"term": "yellow",
"property_ids": [
1
],
"id": 2
}
}
Lastly here is the more like this query I use against it to attempt to 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 issue is when I do this search I get no results back:
{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}%
If I do a standard wildcard query for just "yellow" I get that result back. What am I missing?
By default min_doc_freq
is 5 (check doc) 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. Example:
{
"query": {
"more_like_this": {
"fields": [
"term"
],
"like_text": "yellow",
"min_term_freq": 1,
"min_doc_freq": 1,
"max_query_terms": 12
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With