Skip to content

Commit 6f1b20a

Browse files
authored
Add documentation for MoreLikeThis
1 parent dec56c3 commit 6f1b20a

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

docs/search_dsl.rst

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ to directly construct the combined query:
223223
Filters
224224
~~~~~~~
225225

226-
227226
If you want to add a query in a `filter context
228227
<https://www.elastic.co/guide/en/elasticsearch/reference/2.0/query-filter-context.html>`_
229228
you can use the ``filter()`` method to make things easier:
@@ -435,6 +434,32 @@ should be one of ``term``, ``phrase`` or ``completion`` to indicate which type
435434
of suggester should be used.
436435

437436

437+
438+
More Like This Query
439+
~~~~~~~~~~~~~~~~~~~~
440+
441+
To use Elasticsearch's more_like_this functionality, you can use the MoreLikeThis query type.
442+
443+
A simple example is below
444+
445+
.. code:: python
446+
447+
from elasticsearch_dsl.query import MoreLikeThis
448+
from elasticsearch_dsl Search
449+
450+
my_text = 'I want to find something similar'
451+
452+
s = Search()
453+
# We're going to match based only on two fields, in this case text and title
454+
s = s.query(MoreLikeThis(like=my_text, fields=['text', 'title]))
455+
# You can also exclude fields from the result to make the response quicker in the normal way
456+
s = s.source(exclude=["text"])
457+
response = s.execute()
458+
459+
for hit in response:
460+
print(hit.title)
461+
462+
438463
Extra properties and parameters
439464
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
440465

0 commit comments

Comments
 (0)