java - Elasticsearch combining queries with Boolean query -
java - Elasticsearch combining queries with Boolean query -
i'm trying combine mutiple queries in elasticsearch using boolean query result not i'm expecting. example:
if have next documents (among others):
doc 1: { "name":"iphone 5", "product_suggestions":{ "input":[ "iphone 5", "apple" ] }, "description":"iphone 5 - lastly version", "brand":"apple", "brand_facet":"apple", "state_id":"2", "user_state_description":"almost new", "product_type_id":"1", "current_price":350, "finish_date":"2014/06/20 14:12", "finish_date_ms":1403273520 } doc 2: { "name":"apple ii lisa", "product_suggestions":{ "input":[ "apple ii lisa", "apple" ] }, "description":"make offer , apple ii lisa!!", "brand":"apple", "brand_facet":"apple", "state_id":"2", "user_state_description":"used", "product_type_id":"1", "current_price":150, "finish_date":"2014/06/15 16:12", "finish_date_ms":1402848720 } doc 3: { "name":"iphone 5s", "product_suggestions":{ "input":[ "iphone 5s", "apple" ] }, "description":"iphone 5s 32gb new few scratches bla bla bla", "brand":"apple", "brand_facet":"apple", "state_id":"1", "user_state_description":"new", "product_type_id":"2", "current_price":510.1, "finish_date":"2014/06/10 14:12", "finish_date_ms":1402409520 } doc 4: { "name":"iphone 4s", "product_suggestions":{ "input":[ "iphone 4s", "apple" ] }, "description":"iphone 4s 16gb mint conditions , unlocked network", "brand":"apple", "brand_facet":"apple", "state_id":"1", "user_state_description":"almost new", "product_type_id":"2", "current_price":385, "finish_date":"2014/06/12 16:12", "finish_date_ms":1402589520 }
and if run next query (get documents , facets keyword "apple" finish_date_ms bigger 1402869581)
{ "from" : 1, "size" : 20, "query" : { "bool" : { "must" : { "query_string" : { "query" : "apple", "default_operator" : "and", "analyze_wildcard" : true } }, "must_not" : { "range" : { "finish_date_ms" : { "from" : null, "to" : 1402869581, "include_lower" : true, "include_upper" : false } } } } }, "facets" : { "brand" : { "terms" : { "field" : "brand_facet", "size" : 10 } }, "product_type_id" : { "terms" : { "field" : "product_type_id", "size" : 10 } }, "state_id" : { "terms" : { "field" : "state_id", "size" : 10 } } } }
this returns:
{ "took":5, "timed_out":false, "_shards":{ "total":5, "successful":5, "failed":0 }, "hits":{ "total":1, "max_score":0.18392482, "hits":[ ] }, "facets":{ "brand":{ "_type":"terms", "missing":0, "total":1, "other":0, "terms":[ { "term":"apple", "count":1 } ] }, "product_type_id":{ "_type":"terms", "missing":0, "total":1, "other":0, "terms":[ { "term":1, "count":1 } ] }, "state_id":{ "_type":"terms", "missing":0, "total":1, "other":0, "terms":[ { "term":2, "count":1 } ] } } }
and should homecoming document doc1. if remove range query, returns documents has apple word. if remve "term" query n document returns, presume problem in range query.
can point me in right direction this?
one other of import thing, query implemented in java (if help). thanks! (sory huge post)
i found mistake. (newbie error honest)
the problem not in range query in begging of json: field set 1 result 1 record should 0!!
thanks everything!!
java elasticsearch
Comments
Post a Comment