elasticsearch-py
elasticsearch-py copied to clipboard
search with nested sort results in 0 results
Elasticsearch version (7.17):
elasticsearch-py version (8.12.1):
Description of the problem including expected versus actual behavior: I cannot retrieve results when using a nested field in the sort argument of the search function.
I want to pull a large amount of data from Elasticsearch. Based on my understanding of the documentation, the most recent recommendation is to use the search function, sort by a unique field, then update the search_after argument after each pull to set up the next search until complete. This appears to work when using the _id field. However, this also results in a warning that says sorting by _id is deprecated and will go away, and to use a unique identifier or combination of identifiers within the body. There is a unique combination of fields that are nested within a parent. However, when I try to use a nested sort option, I receive 0 results.
I understand there is likely a by including this in the body, but I wanted to use the function as intended instead.
Steps to reproduce: This is how I am sorting by id:
import elasticsearch as es
username_query_model = {
"range": {"common.eventTime": {"gte": "now-2h", "lte": "now"}},
}
index_data = client.search(
index="my_index",
query=username_query_model,
sort=['_id'],
size=1000
)
This get results and the following warning:
ElasticsearchWarning: Loading the fielddata on the _id field is deprecated and will be removed in future versions. If you require sorting or aggregating on this field you should also include the id in the body of your documents, and map this field as a keyword field that has [doc_values] enabled
Here I am trying to sort by a nested field:
index_data = client.search(
index="my_index",
query=username_query_model,
sort='_parent.child',
size=1000
)
And that has 0 results. Note that there is no error, just no results. I have tried a bunch of different fields, but none of the nested ones work, only the parents.
What I would eventually like to build to is something like the following:
index_data = client.search(
index="my_index",
query=username_query_model,
sort=['_parent.child1', '_parent.child2', '_parent.child3'],
size=1000,
search_after=[x, y, z]
)