I am using a Python client to search an index on Elasticsearch and by default, it is returning only the first 10 hits. I want the first 200 hits instead. It was my understanding that by adding the "size" field in the input query, we can specify how many hits we would like to retrieve.
The code I am using to search is: result=es.search(index="sample_full",query=new_dep_query)
When new_dep_query is as given below, it works fine and I am getting the top 10 hits.
{
"bool": {
"must": [
{
"match": {
"field1": "no"
}
}
]
}
}
But when I change the format of the query as pointed out by previous stack overflow answers to the following format, I get errors.
{
"query": {
"bool": {
"must": [
{
"match": {
"field1": "no"
}
}
]
}
}
}
The error I get is:
Traceback (most recent call last):
File "/Users/xxxx/Desktop/project/integ1/sample_finder.py", line 76, in <module>
result=es.search(index="sample_full",query=new_dep_query)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/elasticsearch/_sync/client/utils.py", line 414, in wrapped
return api(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/elasticsearch/_sync/client/__init__.py", line 3859, in search
return self.perform_request( # type: ignore[return-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/elasticsearch/_sync/client/_base.py", line 320, in perform_request
raise HTTP_EXCEPTIONS.get(meta.status, ApiError)(
elasticsearch.BadRequestError: BadRequestError(400, 'parsing_exception', 'unknown query [query]')
How do I resolve this error and add a size parameter in the Elasticsearch request from a Python client
Did you try like this?
es.search(index= idx-name, size='100', body=query)