Wildcard field names in filter?


#1

To provide an example, I have data that looks like this:

"example": {
    "abc": {
        "field1":"value1"
    },
    "def": {
        "field1":"value2"
    },
    "xyz": {
        "field1":"value3"
    }
}

I want to do a filter to return all documents where one of the objects nested in "example" has a "field1" of "value1". The complicating factor here is that the field names "abc," "def," and "xyz" are dynamic, so I can't do a term filter like "example.abc.field1 : value1", since I don't know the field name "abc". What I need is something like "example.*.field1 : value1". Is this possible to do in Elasticsearch?

I've also been looking into the has_child filter, but it appears that, unless I'm mistaken, this only works with arrays rather than objects. I know I could structure the field as an array and that would achieve the desired result, but that makes things difficult in the application layer since it requires me to iteratively search the array to find "example.xyz", which is not very scalable.

Thanks for your help!


(Jason Wee) #2

think so, for querystring, there is a wildcard field specifier https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_multi_field_2

hth


#3

Thanks for your response. That is correct, but I was looking for a filter that does this rather than a query. Either way I ended up deciding to go with a different approach.


(system) #4