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