More Like This Query not giving any hits


I recently upgraded to 2.1 and I am trying to use the new more like this query without any luck. My code looks something like this:

  function_score: {
     functions: [...],
       query: {
           bool: {
             must: [{
                            more_like_this : {
                                fields : ['title', 'desc'],
                                like : [
                                        "_index" : "myindex",
                                        "_type" : "mytype",
                                        "_id" : "uniqueid"
                                min_term_freq : 1,
                                max_query_terms : 12
             must_not: [...],
             should: [...],
             filter: [...],

(Michael McCandless) #2

Try simplifying your query (remove the bool and run only the more_like_this)?

If you pass a canned string as the like instead of referencing an already indexed document, does it work?


Yes anything else is working fine, I was using multi match (cross fields) for text searches. However, for this particular task I need to search documents similar to a particular document. Don't know why this is not working. In version 1.4 I think it was working fine with the filtered api.

(sandro) #4

I got something similar to work with the keys in a bit a different order and also I think it is better to use ids instead of like (following docs I also thought that I needed like, but did not get it to work till I used ids). My working example in a python dict is the following, where I do a bool query with more_likeThis with own rescoring as one must clause an matching another field as another must clause:
{'query': {'bool': {'must': [{'function_score': {'functions': [{'filter1':11,[..]},{'filter2':22,[..]}], 'query': {'more_like_this': { 'fields': ["myfields"] 'ids': 123,#instead of like 'max_query_terms': 52, 'min_term_freq': 2, 'minimum_should_match': '25%', 'stop_words':[..]}} 'score_mode': '..' }}, {'terms': {'myspecialField: ['matchThis']}}]}}}


Seems to be working somewhat but it is giving me unexpected results. The matches don't look accurate.

(sandro) #6

Could it be due to the params you give to more like this? I found it very useful to check what this query actually does via using validate, see more like this exple here. For instance I could imagine that
min_term_freq : 1, max_query_terms : 12
could imply that you have only VERY specific terms to the mother-document to be matched by other docs

(system) #7