Please, explain how to achieve more-like-this functionality.
This what works via the REST (POST to http://localhost:9200/_search):
{
"query": {
"more_like_this" : {
"fields" : ["content", "summary"],
"like" : [
{
"_index" : "article",
"_type": "article_document",
"_id" : "118"
}
],
"min_term_freq" : 1,
"max_query_terms" : 12
}
}
}
from elasticsearch_dsl.query import MoreLikeThis
from elasticsearch_dsl Search
my_text = 'I want to find something similar'
s = Search()
s = s.query(MoreLikeThis(like=my_text, fields=['content', 'summary']))
# You can also exclude fields from the result to make the response quicker in the normal way
# s = s.source(exclude=["sentences", "text"])
response = s.execute().to_dict()
@eamonnmag:
Awesome! Thanks. Do you perhaps know how to do it based on the id of the document (+index, +type), like in my example?
s = Search()
s = s.query(MoreLikeThis(like={'_id': 118, '_index': 'article', '_type': 'article_document'}, fields=['content', 'summary']))
print(s.to_dict())
This gives you
{'query': {'more_like_this': {'like': {'_id': 118, '_index': 'article', '_type': 'article_document'}, 'fields': ['content', 'summary']}}}
Which is the query you have there.
@eamonnmag:
Awesome! Thanks for you help.
Most helpful comment
This gives you
Which is the query you have there.