1

I've following data in elastic search

  {
      "took": 1,
      "timed_out": false,
      "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
      },
      "hits": {
        "total": 1,
        "max_score": 1,
        "hits": [
          {
            "_index": "<index>",
            "_type": "<type>",
            "_id": "75559264",
            "_score": 1,
            "_source": {
              "request": {
                "parts": [
                  {
                    "lineCode": "GAT",
                    "partId": 0,
                    "reQty": 1,
                    "description": "Serpentine Belt",
                    "partNumber": "K040398",
                    "lineNumber": 1,
                    "brand": "BBSC"
                  },
                  {
                    "lineCode": "GAT",
                    "partId": 0,
                    "reQty": 1,
                    "description": "Timing Belt Kit With Water Pump",
                    "partNumber": "TCKWP312",
                    "lineNumber": 30,
                    "brand": "BBSC"
                  }, <and so on>
                ]
              },
              "response": {
                "parts": [
                  {
                    "lineCode": "AC",
                    "partId": 0,
                    "reQty": 1,
                    "description": "Serpentine Belt",
                    "partNumber": "4K398",
                    "locations": [
                      {
                        "core": 0,
                        "cost": 10,
                        "called": "Store 4",
                        "availQty": 4,
                        "list": 12
                      },
                      {
                        "core": 0,
                        "cost": 10,
                        "called": "Store 5",
                        "availQty": 5,
                        "list": 12
                      }
                    ],
                    "lineNumber": 13,
                    "brand": "BCVC",
                    "status": "Original"
                  },<and so on>
                ]
              },
              "header": {
                "lookup": "EPE",
                "ymme": "2001 HONDA CIVIC 4-1668 1.7L SOHC",
                "transid": "1a97ebd4-514c-43be-be19-2121f2d2b452",
                "created": "2017-12-01T05:37:32",
                "channel": "Pb",
                "errFlg": 0,
                "action": "INQ",
                "id": 75559264
              },
              "documentTimeStamp": "2017-12-01T05:37:47.668+0000"
            }
          }
        ]
      }
    }

Now I want to fetch the data(corresponding parts ) as per linecode (eg: "GAT").

I've gone through with this document and executed the following query

GET <myindex>/<type>/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "path": "request.parts",
            "score_mode": "max", 
            "query": {
              "bool": {
                "must": [
                  {
                    "match": {"parts.lineCode": "GAT"}
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}

But here I'm not getting any data instead it is showing the following response.

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}

I'm new to the elastic search. so any help for getting data as per my requirement is so much appreciated.

Thanks in advance!! :)

2
  • Which version of Elasticsearch? Commented Feb 19, 2018 at 10:56
  • Elastic search is of version 5.1.1 Commented Feb 19, 2018 at 11:26

1 Answer 1

0
GET your_index/your_index_type/_search
{
  "query": {
    "nested": {
      "path": "request.parts",
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "request.parts.lineCode": "GAT"
              }
            }
          ]
        }
      }
    }
  }
}

This Should work Veswanth !!!!!!!!!!!!

Sign up to request clarification or add additional context in comments.

3 Comments

No its not prasad!
@prasad kp We have talked in chat no the problemis that both request and parts are nested
@Lupanoide okay got it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.