Initially, I had some documents with inner objects in them and I was performing queries that returned reasonable results.
In order to perform queries on those inner objects correctly with multiple required conditions (like ConditionA AND ConditionB
) I have decided to convert some of the inner objects into nested objects and reindex the data.
Now, I am noticing many weird behaviors while performing queries. One is this:
Query:
POST documents\_search
{
"query": {
"term": {
"copies.idOwnedByGroup": 1
}
}
}
Result:
Query:
POST documents\_search
{
"query": {
"match_all": {
}
}
}
One of the results:
The copies
object is a nested object. Here is the mapping:
Why doesn't the first query find this document? This seemed to work with copies
not being a nested object.
I am also using the OpenSearch.Client
library and that also produces similar queries that don't seem to work anymore.
When I try this, it seems to work (it returns many matching results):
POST documents\_search
{
"query": {
"nested": {
"path": "copies",
"query":{
"term": {
"copies.idOwnedByGroup": 1
}
}
}
}
}
But I have some questions:
- Does this mean I have to perform ONLY nested queries on data inside nested objects? It is weird that no error is returned from the non-nested query if that is the case...
- Do I continue using non-nested queries for data outside of nested objects?
- What if I have a nested object inside another nested object? Do I specify the first nested object's path as
path
and OpenSearch figures things out when it comes to the inner nested object? - I have many other queries that fail now because of nested objects, and I am not sure if the above change will solve them all. Is there anything else I need to pay attention to in this case?
I have the answers:
path
.