I have a very basic Django API which makes a query in elasticsearch. The output shows the query_parameters and the search.query.
Why I cannot pass the country variable in this case 'DE' to the search.query as shown in the output?
Could you please explain the implications of [] in country[]?
class ESNumView(APIView):
"""Obtain number of articles after a search in titles and abstract in ES"""
def get(self, request, *args, **kwargs):
query = self.request.query_params.get('query')
country = self.request.query_params.get('country')
print(self.request.query_params)
search = Search(index=constants.ES_INDEX)
q = Q('bool',
must=[
Q('multi_match', query=query, fields=['title', 'abstract']),
Q('terms', country=country)
]
)
s = search.query(q)
pprint(s.to_dict())
num_count = s.count()
return Response(data=[{'search_count': num_count}])
The output is;
<QueryDict: {'query': ['membrane'], 'country[]': ['DE']}>
{'query': {'bool': {'must': [{'multi_match': {'fields': ['title', 'abstract'], 'query': 'membrane'}}, {'terms': {'country': None}}]}}}