elasticsearchlucenemorelikethis

Elastic search - More Like this query returning empty result


I'm using Elastic search to create some sort of tag engine. I'm inserting a document and I can't retrieve it. My steps to reproduce the issue:

1) Create index:

PUT index
{
"mappings": {
    "taggeable" : {
        "_all" : {"enabled" : false},
        "properties" : {
            "id" : {
                "type" : "string",
                "index" : "no"
            },
            "tags" : {
                  "type" : "text"
            }
            }
        }
    }
}

2) Insert document:

POST index/taggeable
{
"id" : "1",
"tags" : "tag1 tag2"
}

3) Query using More like This:

GET index/_search
{
"query": {
    "more_like_this" : {
        "fields" : ["tags"],
        "like" : ["tag1"],
        "min_term_freq" : 1
    }
}
}

But I'm receiving:

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

Anyone knows what I'm doing wrong? I should retrieve the document I inserted.


Solution

  • You set up the parameter

    min_term_freq

    The minimum term frequency below which the terms will be ignored from the input document. Defaults to 2.

    which is good, since otherwise it will be defaulted to 2. There is also a parameter

    min_doc_freq

    The minimum document frequency below which the terms will be ignored from the input document. Defaults to 5.

    In your case, if you have just 1 document, this will be ignored, so you either need to add more docs, or specify parameter min_doc_freq to 1