i have particular issue concerning querying on boolean field , string field nested array field. index mapping follow:
indexes :string_field_1, type: 'string' indexes :string_field_2, type: 'string' indexes :boolean_field_1, type: 'boolean' indexes :array_field_1 indexes :boolean_field_2, type: 'boolean' indexes :string_field_3, type: 'string' end indexes :array_field_2 indexes :integer_field_1, type: 'integer' end indexes :array_field_3 indexes :integer_field_2, type: 'integer' end
the document index has many other fields not nested array field, have included among query fields. have tried approach using filter , bool queries follow:
"query": {"bool": {"must": [ {"query_string": {"query":"text being searched", "fields":[ "string_field_1", "string_field_2", "array_field_1.string_field_3" ], "fuzziness":"1","analyze_wildcard":true,"auto_generate_phrase_queries":false,"analyzer":"brazilian","default_operator":"and"} } ], "filter":[ {"bool": {"must": [ {"bool": {"should": [ {"term":{"boolean_field_1":false}}, {"terms":{"array_field_2.integer_field_1":[x,z]}}, {"term":{"array_field_3.integer_field_2":y}}]}}, {"bool": {"should": [ {"term":{"array_field_1.boolean_field_2":true}}, {"terms":{"array_field_2.integer_field_1":[x,z]}}, {"term":{"array_field_3.integer_field_2":y}}]}}, ] } } ] } } ] } }
the problem query is returning document which, in opinion, doesn't have returned. document, in case, bellow:
_source": { "string_field_1": "text 1", "string_field_2": "text 2", "boolean_field_1": false, "array_field_1": [ { "boolean_field_2": true, "string_field_3": "some text not being searched" }, { "boolean_field_2": true, "string_field_3": "some text not being searched" }, { "boolean_field_2": false, "string_field_3": "text being searched" }, { "boolean_field_2": true, "string_field_3": "some text not being searched" } ], "array_field_2": [ { "integer_field_1": } ], "array_field_3": [ { "integer_field_2": b } ] }
as can notice, third item of array_field_1 contains boolean_field_2: false , text being searched. but, according filter: clause, documents array_field_1.boolean_field_2 true have retrieved, unless array_field_2.integer_field_1: or array_field_3.integer_field_1 occurs, not true, according query part. seems elastic not considering array_field_1[2] 1 boolean_field_2 false. how can make query document isn't retrieved?
thanks advance, guilherme
that solution:
"query":{ "bool":{ "should": [ { "query_string": { "query":"text being searched", "fields": [ "string_field_1", "string_field_2" ], "fuzziness":"1","analyze_wildcard":true,"auto_generate_phrase_queries":false,"analyzer":"brazilian","default_operator":"and" } }, { bool: { should:[ { query:{ nested: { path: 'array_field_1', query: { bool: { must: [ { match: { "array_field_1.string_field_3": "text being searched"} }, {term: {"array_field_1.boolean_field_2": true}} ] } } } } }, { bool: { must: [ { query:{ nested: { path: 'movimentos', query: { bool: { must: [ { match: { "array_field_1.string_field_3": "text being searched"} }, {term: {"array_field_1.boolean_field_2": false ] } } } } }, { query: { bool: { should: [ {"terms":{"array_field_2.integer_field_1":[x,z]}}, {"term":{"array_field_3.integer_field_2":y}} ] } } } ] } } ] } } ] } }
Comments
Post a Comment