Please find below my iPython shell statements:
In [90]: s = Search(using=client, index='institutes')
In [91]: s = s.filter('match_phrase',country__uri='canada').filter("nested", path="institutecourse_set", query=Q("match_phrase", **{'institutecourse_set.stream.uri': 'sciences'}))
In [92]: di = s.to_dict()
In [93]: s1 = Search(using=client, index='institutes')
In [94]: s1 = s1.from_dict(di)
In [95]: s1.count()
Out[95]: 84
In [96]: s.count()
Out[96]: 42
My basic requirement was to construct a query using high level library elasticsearch-dsl-py in django project based on several inputs and filter criteria.
For being self-explainable and easy to construct code, I made up the query into dictionary(json) style like basic elasticsearch queries are, then I utilize the "from_dict(dictionary_object)" method from elasticsearch_dsl library and call count() and execute() on the result for my purposes.
The above shown is a smaller example, but the problem is clearly visible. Using the from_dict am getting double the results as to when I use the high level syntax(the answer 42 above is correct), can anyone explain why so?