-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Response filtering using negative filter_path is removing too many fields by skipping empty arrays #63842
Comments
Pinging @elastic/es-core-infra (:Core/Infra/REST API) |
I briefly looked into this. Response filtering is known not to preserve empty objects and arrays, unfortunately, since it is supported in Elasticsearch. I also find it counter intuitive. The reason for this is that this is how the library that we use to parse json (and other formats) implements filtering: only when there is a value, it checks if the property needs to be added. |
@javanna Thanks for the context. Are you saying we should document the existing behavior instead of changing it? |
@wylieconlon not sure yet, I don't think my quick analysis is enough to get to a conclusion, but I wanted to point out that this may seem an easy bug to fix at first glance but it is not in practice. If all you'd need response filtering for is trimming down aggregations response is #63898 , which seems doable and also cleaner. |
This change updates our support for filtering so that empty arrays and objects are preserved when they are present in the content that is filtering. Closes elastic#63842
@jaymode pinged me on this and I was already looking at xcontent so I had to trace through the code. The behavior is a little more precisely described as "if a filter could match an empty object or array it will be removed". The code looks very keen to remove the whole path to something if the whole thing is filtered. We're all used to this. It just that the filter can't tell the difference between when the whole result was filtered out and when it received an empty string or array. I opened FasterXML/jackson-core#715 to talk about this over there. |
We ended up merging support to jackson-core to opt into or out of this behavior on a very granular level. So, once Jackson 2.14 is released, we can upgrade and fix this issue on our side. Now, we're blocked on upgrading jackson because of Azure, but this is another thing waiting on it.... |
Elasticsearch version 8.0 snapshot
Description of the problem including expected versus actual behavior:
I am trying to reduce the JSON payload from ES to Kibana by up to 50%. One part of this is that I'm trying to use a negative
filter_path
parameter to exclude one particular path,-**.key_as_string
. The bug is that the response filtering is not as targeted as it should be, and it's removing other empty fields.Steps to reproduce:
This reproduction works for any index, and it will exclude the
hits: []
response property which I was expecting to have.a. Query showing full response
{"took":0,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":10000,"relation":"gte"},"max_score":null,
"hits":[]
}}
b. Same query with response filtering
{"took":2,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":10000,"relation":"gte"},"max_score":null}}
Notice that the
hits: []
is no longer returned.The text was updated successfully, but these errors were encountered: