flex icon indicating copy to clipboard operation
flex copied to clipboard

Using More Like This

Open rickthomasjr opened this issue 12 years ago • 1 comments

How do I pass in the parameters that make mlt useful (like mlt_fields and min_doc_freq)?

rickthomasjr avatar Oct 21 '13 00:10 rickthomasjr

Hi Rick, If you want to use the provided API method, you should pass the :data variable (which pass any structure you like as the structure body of the request).

For example:

Flex.more_like_this :type => 'the_type', :id => 'the_id', :data => {:fields => [:a, :b]}

If you have a lot of data to pass, then it might be probably better just write your own template (not a search-template though), eventually with some default, for example:

my_mlt:
  - GET
  - /<<index>>/<<type>>/<<id>>/_mlt
  - fields: <<fields>>
    min_term_freq: <<:min_term_freq= 1 >>,
    max_query_terms: <<max_query_terms= 10 >>

The search template is the way to go if you want to use the more_like_this query instead of the API. For example:

my_query:
  query:
    bool:
      must:
      - query_string:
          query: <<q= '*' >>
      - more_like_this:
          like_text: <<like_text= ~ >>
          fields: <<like_fields= ~ >>

Notice that the :like_text and the like_fields in this example are optional, so when you don't pass them the more_like_this structure branch will be pruned.

HTH

ddnexus avatar Oct 21 '13 02:10 ddnexus