Nested search query in Elasticsearch with range filter and unknown names of inner fields -
i storing data in elasticsearch database , trying query it, filtered range of numbers.
this minimized structure of document in database:
"a": { "b": { "x": [1, 2, 3, 4], // note: x, y , z not compulsory "y": [2, 3, 4], // documents can have x or z or maybe x , z etc. "z": [5, 6] } }
now want query return documents, there in of subfields of "b" @ least 1 number in range between 2 , 4. important thing here don't know names of subfields of "b".
the query came is:
post /i/t/_search { "query": { "query_string": { "fields": ["a.b.*"], "query": "number:[2 4]" } } }
the query doesn't rise error, returns no result. not sure, kind of search query appropriate such task. used query string because 1 found join unknown field name , range.
try remove number:
in query:
{ "query": { "query_string": { "fields": ["a.b.*"], "query": "[2 4]" } } }
optionally try count:[2 4]
(docs)
another type of query allows use * wildcard in field path multi match query don't see how combine numeric range in case. thing comes mind :
{ "query": { "bool": { "should": [ { "multi_match": { "query": "2", "fields": ["a.b.*"] } }, { "multi_match": { "query": "3", "fields": ["a.b.*"] } }, { "multi_match": { "query": "4", "fields": ["a.b.*"] } } ] } } }
... pretty ugly. first solution query_string short , powerful.
Comments
Post a Comment