49398

Not getting all the results

Question:

This is my question related to my previous question that I asked <a href="https://stackoverflow.com/questions/10783994/search-stops-after-the-first-match#comment14130234_10783994" rel="nofollow">search stops after the first match</a>

Here I am giving you the mapping.

{ "copy_order_snapshot": { "properties": { "line_item_info": { "dynamic": "true", "properties": { "m_product_details": { "dynamic": "true", "properties": { "accessories_colour": { "type": "string" }, "status": { "type": "string" } } }, "other_details": { "dynamic": "true", "properties": { "accessories_material_type": { "type": "string" } "status": { "type": "string" } } }, "product_details": { "dynamic": "true", "properties": { "accessories_colour": { "type": "string" }, "status": { "type": "string" } } } } }, "order_data": { "dynamic": "true", "properties": { "state": { "type": "string" }, "status": { "type": "string" } } } } } }

In my previous question I was talking about attribute_set_id , here the same case is with status. The order_details->status is "enabled" while the other status are as "1" and "canceled". When I search for

{ "query":{ "term":{ "status":"enabled" } } }

I get the result

but if I search for

{ "query":{ "term":{ "status":"1" } } }

or

{ "query":{ "term":{ "status":"canceled" } } }

I get no results.

Please help.

Answer1:

It happens because of ambiguous field name "status". During query processing, elasticsearch resolves the field name "status" into the first fully qualified field name that it matches. When I ran it on my machine, it got resolved into line_item_info.other_details.status.

$ curl "localhost:9200/test-orders/_validate/query?q=status:blah&explain=true&pretty=true" { "valid" : true, "_shards" : { "total" : 1, "successful" : 1, "failed" : 0 }, "explanations" : [ { "index" : "test-orders", "valid" : true, "explanation" : "line_item_info.other_details.status:blah" } ] }

If you want your query to match all status fields, you might need to use fully qualified names (such as line_item_info.other_details.status, line_item_info.m_product_details.status, etc.) and combine them using <a href="http://www.elasticsearch.org/guide/reference/query-dsl/dis-max-query.html" rel="nofollow">Dis Max</a> or <a href="http://www.elasticsearch.org/guide/reference/query-dsl/bool-query.html" rel="nofollow">Bool Queries</a>.

For example:

$ curl -XGET http://localhost:9200/test-orders/copy_order_snapshot/_search -d '{ "query":{ "bool" : { "should" : [ { "term" : { "line_item_info.m_product_details.status" : "1" } }, { "term" : { "line_item_info.other_details.status" : "enabled" } } ] } } }'

Recommend

  • how to create simple image slider / accordion ?
  • WCF Data Services join query
  • intermittent error returning an internal reference with boost.python
  • How to make this multidimensional array into three specified parts?
  • Catch exception in ctypes based on C-exit code
  • Cannot assign method group to an implicitly-typed local variable in asp.net,linq,c#
  • Train corpus for NER with NLTK ieer or conll2000 corpus
  • Could an iterative function call itself?
  • how to cast an anonymous type to IQueryable in C#?
  • Android - How to generate touch event from javascript?
  • Delete file in internal memory from Android device?
  • Sliding transition animation between Screens in Caliburn Micro
  • wrong item changes in recyclerview
  • First time running a ASP site, and getting server error in '/' Application
  • Change border corlor of NSTableView
  • How to edit css for jquery datepicker prev/next buttons?
  • Spring Web Flow exception handling
  • Angular Ui-router can't access $stateParams inside my controller
  • How do we generate stack trace in TOMCAT?
  • Subversion reverting resolved file
  • QPushButton is not changing the background-color proper
  • How to synchronize two scrollview in Android?
  • Creating a C++ function that calls other Lua function
  • INSERT EXEC Statement cannot be nested [duplicate]
  • Losing my session variables
  • Responsive left sidebar open close
  • Symfony 2 error page response
  • C#: Import/Export Settings into/from a File
  • Which open source license has no forking [closed]
  • How Get arguments value using inline assembly in C without Glibc?
  • How to make R's read_csv2() recognise the text characters properly
  • Implementation of State Monad
  • Alternative to overridePendingTransition() - Android
  • How do I pass the string value parameter of the selected list item from an auto-populated dropdown l
  • recyclerView does not call the onBindViewHolder when scroll in the view
  • JSON with duplicate key names losing information when parsed
  • How to make Safari send if-modified-since header?
  • How to pass list parameters for each object using Spring MVC?
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • JaxB to read class hierarchy