Not getting all the results

This is my question related to my previous question that I asked search stops after the first match

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.

Answers


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 Dis Max or Bool Queries.

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" }
                }
            ]
        }
    }
}'

Need Your Help

Determine array size

excel-vba vba excel

I currently facing a problem on how to determine the size of array after looping ends. Below is my coding for that particular function.

Setting up java configurations in eclipse. multiple .param files

java eclipse genetic-programming evolutionary-algorithm

I'm going to be using ECJ for doing genetic programming and I haven't touched java in years. I'm working on setting up the eclipse environment and I'm catching a few snags.