Home > Mobile >  Elastic search un-searchable feild?
Elastic search un-searchable feild?

Time:05-18

I have an index with a mapping field of type text, its called ean_code, but when I try to retrieve documents querying this field, it says 0 results.

I am running the command:

GET <index-name>/_doc/1877

This gives me back: enter image description here

I can clearly see the ean_code is there, but when I try running this query:

POST <index-name>/_search
{
  "query": {
    "match": {
      "product_sale_elements.ean_code": {
        "query": "9004464248405"
      }
    }
  }
}

It says 0 hits. What am I missing? Why can't this field be searched upon?

Here is the mapping: enter image description here

CodePudding user response:

Since product_sale_elements is of type nested you need to use a nested query, like this:

POST <index-name>/_search
{
  "query": {
    "nested": {
      "path": "product_sale_elements",
      "query": {
        "match": {
          "product_sale_elements.ean_code": {
            "query": "9004464248405"
          }
        }
      }
    }
  }
}
  • Related