Elasticsearch query returning zero results

Viewed 66

I am relatively new to Elasticsearch. I am storing records in my ES index using the following POST request on Postman

http://localhost:9200/boqss/_doc/6
{
    "projectId" : "KLMN",
    "boqList" : [ 
       {

            "particulars" : "Providing & Casting R.C.C M25",
            "quantity" : 900,
            "unit" : "m3",
            "rate" : 8000,
            "amount" : 7200000
        }
        ]

}

When I perform a search query like this

http://localhost:9200/boqss/_search

I get the following response :

"hits": [
            {
                "_index": "boqss",
                "_type": "_doc",
                "_id": "1",
                "_score": 1.0,
                "_source": {
                    "projectId": "ABCD",
                    "boqList": [
                        {
                            "particulars": "Excavation ",
                            "quantity": 1500,
                            "unit": "m3",
                            "rate": 500,
                            "amount": 750000
                        }
                    ]
                }
            },
            {
                "_index": "boqss",
                "_type": "_doc",
                "_id": "2",
                "_score": 1.0,
                "_source": {
                    "projectId": "ABCD",
                    "boqList": [
                        {
                            "particulars": "Providing & laying Rubble Soling",
                            "quantity": 300,
                            "unit": "m2",
                            "rate": 450,
                            "amount": 135000
                        }
                    ]
                }
            },

           ...

However, when I perform another search query like the following :


http://localhost:9200/boqss/_search
{
      "query":{
      "match" : {
         "particulars":"Excavation"
      }
   }
}

I get zero hits with a response as follows :


{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 0,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    }
}

How can I make sure that I retrieve the 'Excavation' entry? Any help would be greatly appreciated. Thank you!

1 Answers

Good start!! You just need to use the fully-qualified field name boqList.particulars:

{
      "query":{
      "match" : {
         "boqList.particulars":"Excavation"
      }
   }
}
Related