3

I have a 'MovieDoc' document and inside it a ListField called 'actors' that contains a list of ObjectFields with properties such as 'last_name', 'first_name', 'country,' etc.

When running a query with Django ElasticSearch DSL, I would like to filter movies by the number of actors they feature (i.e. by the length of the values in the 'actors' ListField).

As far as I understand, this should be done using script-filtering (https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-using.html).

However, I do not understand how I can apply the ElasticSearch script filtering with django-elasticsearch-dsl. I have tried something like this in different combinations but to no avail:

search_query = 'battle'
results = MovieDoc.search().query(search_query).filter(script={"script": ["doc['actors'].values.size() > 1"]})

1 Answer 1

0

You can filter as following:

.filter("script", script="doc['actors'].values.size() > 1")

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.