Query_shard_exception

I am getting below error when I am trying to query :slight_smile :
{
"error": {
"root_cause": [
{
"type": "query_shard_exception",
"reason": "failed to create query: [nested] failed to find nested object under path [product]",
"index_uuid": "taZ8q8FPT2OTbpD4nNF_PA",
"index": "stores"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "stores",
"node": "ceqDO_ZlR06XQ-vNlnyn5A",
"reason": {
"type": "query_shard_exception",
"reason": "failed to create query: [nested] failed to find nested object under path [product]",
"index_uuid": "taZ8q8FPT2OTbpD4nNF_PA",
"index": "stores",
"caused_by": {
"type": "illegal_state_exception",
"reason": "[nested] failed to find nested object under path [product]"
}
}
}
]
},
"status": 400



Query:
GET stores/_search
{
"query": {
"nested": {
"path": "product",
"query": {
"bool": {
"must": [
{"match": {"product.product.keyword": "Mustang"}}
]
}
}
}
}
}


cluster: Single node Cluster

Welcome to our community! :smiley:

What is the mapping of the index?
Also please format your code/logs/config using the </> button, or markdown style back ticks. It helps to make things easy to read which helps us help you :slight_smile:

Thanks mark

here is the mapping:

{
  "stores": {
    "mappings": {
      "properties": {
        "product": {
          "properties": {
            "product": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "quantity": {
              "type": "long"
            }
          }
        },
        "suburb": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        }
      }
    }
  }
}

What version of Elasticsearch are you running?

version 8.6

Can you please get the mappings from the index you are querying? The mappings you specified seem to contain a mapping conflict (product field mapped both as object and string), which I believe should cause an error.

Mapping

PUT job 
{
  "mappings": {
    "properties": {
      "desingnation":{
        "type": "keyword"
      },
      "skills":{
        "type": "nested"
      }
    }
  }
}

Doc


POST job/_doc
{
  "desingnation": "ELK",
  "skills": [
    {
      "core": "developer",
      "experience": 10
    },
    {
      "core": "administrator",
      "experience": 5
    }
  ]
}
POST job/_doc
{
  "desingnation": "Monitoring",
  "skills": [
    {
      "core": "developer",
      "experience": 10
    },
    {
      "core": "consultant",
      "experience": 6
    }
  ]
}

SEARCH

GET job/_search
{
  "query": {
    "nested": {
      "path": "core",
      "query": {
        "bool": {
          "must": [
            {"match": {"skills.core.keyword": "developer"} }
          ]
        }
      }
    }
  }
}

ERROR

 "error": {
    "root_cause": [
      {
        "type": "query_shard_exception",
        "reason": "failed to create query: [nested] failed to find nested object under path [core]",
        "index_uuid": "mg-w1GaURISAzlDsfAxhYw",
        "index": "job"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "job",
        "node": "ceqDO_ZlR06XQ-vNlnyn5A",
        "reason": {
          "type": "query_shard_exception",
          "reason": "failed to create query: [nested] failed to find nested object under path [core]",
          "index_uuid": "mg-w1GaURISAzlDsfAxhYw",
          "index": "job",
          "caused_by": {
            "type": "illegal_state_exception",
            "reason": "[nested] failed to find nested object under path [core]"
          }
        }
      }
    ]
  },
  "status": 400
}


In order to run a nested query you need to have it nested in your mapping as well.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.