ben.IT
ben.IT

Reputation: 1610

Elastich search : more_like_this operator returns no hit

I am trying to find similar documents to one document in elastic search (the document with id '4' in this case) in my sandbox based on a field (the 'town' field in this case). So i wrote this query, which returns no hit :

GET _search
{
       "query": {
        "more_like_this" : {
            "fields" : ["town"],
            "docs" : [
            {
                "_index" : "app",
                "_type" : "house",
                "_id" : "4"
            }
            ],
            "min_term_freq" : 1,
            "max_query_terms" : 12
        }
    }
}

In my dataset, the document #4 is located in a town nammed 'Paris'. Thus when I run the following query, the document #4 is in the hits results with a lot of others results :

GET _search
{
    "query": {
             "match": { "town": "Paris" }
    }
}

I don't understand why the 'more_like_this' query does not return results whereas there are other documents that have a field with the same value. I precise that I check the _index, _type and _id parameters using the '"match_all": {}' query.

It looks like the second example of this official elastic search ressource : http://www.elastic.co/guide/en/elasticsearch/reference/1.5/query-dsl-mlt-query.html

What's wrong with my 'more_like_this' query ?

Upvotes: 0

Views: 367

Answers (1)

Vineeth Mohan
Vineeth Mohan

Reputation: 19253

I am assuming you have only a less number of documents. In that case , can you give min_doc_freq as 0 and try again. Also use POST for search -

POST _search
{
       "query": {
        "more_like_this" : {
            "fields" : ["town"],
            "docs" : [
            {
                "_index" : "app",
                "_type" : "house",
                "_id" : "4"
            }
            ],
            "min_term_freq" : 1,
            "max_query_terms" : 12,
            "min_doc_freq" : 1
        }
    }
}

Upvotes: 2

Related Questions