Search code examples
elasticsearchkibanaelastic-stackelasticsearch.net

Elastic Search query is giving a error "All shared Failed" "Failed to create query


I am new to elastic search query, the query is showing error when i execute the query using kibana console the query is

GET /_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "languageSkills.languageId": "10"
          }
        }
      ],
      "must_not": [
        {
          "term": {
            "RemoveFromPositions": "Guid_Value_Here"
          }
        },
        {
          "nested": {
            "path": "positions",
            "query": {
              "bool": {
                "must": [
                  {
                    "term": {
                      "positions.PositionID": "Guid_Value_here"
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}

The exception i am getting is, i have no idea why i am getting this, i have been using this for a long time, then i upgraded my elastic search and kibana both after that i am facing this issue

{
  "error": {
    "root_cause": [
      {
        "type": "query_shard_exception",
        "reason": "failed to create query: {\n  \"bool\" : {\n    \"must\" : [\n      {\n        \"term\" : {\n          \"languageSkills.languageId\" : {\n            \"value\" : \"10\",\n            \"boost\" : 1.0\n          }\n        }\n      }\n    ],\n    \"must_not\" : [\n      {\n        \"term\" : {\n          \"RemoveFromPositions\" : {\n            \"value\" : \"12fv567a-1ede-2f0-a75a-d1d236dcb38f\",\n            \"boost\" : 1.0\n          }\n        }\n      },\n      {\n        \"nested\" : {\n          \"query\" : {\n            \"bool\" : {\n              \"must\" : [\n                {\n                  \"term\" : {\n                    \"positions.PositionID\" : {\n                      \"value\" : \"12fv567a-1ede-2f0-a75a-d1d236dcb38f\",\n                      \"boost\" : 1.0\n                    }\n                  }\n                }\n              ],\n              \"adjust_pure_negative\" : true,\n              \"boost\" : 1.0\n            }\n          },\n          \"path\" : \"positions\",\n          \"ignore_unmapped\" : false,\n          \"score_mode\" : \"avg\",\n          \"boost\" : 1.0\n        }\n      }\n    ],\n    \"adjust_pure_negative\" : true,\n    \"boost\" : 1.0\n  }\n}",
        "index_uuid": "eCFSSERoQ-a1jAW4_-ccJg",
        "index": ".kibana_1"
      },
      {
        "type": "query_shard_exception",
        "reason": "failed to create query: {\n  \"bool\" : {\n    \"must\" : [\n      {\n        \"term\" : {\n          \"languageSkills.languageId\" : {\n            \"value\" : \"10\",\n            \"boost\" : 1.0\n          }\n        }\n      }\n    ],\n    \"must_not\" : [\n      {\n        \"term\" : {\n          \"RemoveFromPositions\" : {\n            \"value\" : \"12fv567a-1ede-2f0-a75a-d1d236dcb38f\",\n            \"boost\" : 1.0\n          }\n        }\n      },\n      {\n        \"nested\" : {\n          \"query\" : {\n            \"bool\" : {\n              \"must\" : [\n                {\n                  \"term\" : {\n                    \"positions.PositionID\" : {\n                      \"value\" : \"12fv567a-1ede-2f0-a75a-d1d236dcb38f\",\n                      \"boost\" : 1.0\n                    }\n                  }\n                }\n              ],\n              \"adjust_pure_negative\" : true,\n              \"boost\" : 1.0\n            }\n          },\n          \"path\" : \"positions\",\n          \"ignore_unmapped\" : false,\n          \"score_mode\" : \"avg\",\n          \"boost\" : 1.0\n        }\n      }\n    ],\n    \"adjust_pure_negative\" : true,\n    \"boost\" : 1.0\n  }\n}",
        "index_uuid": "ncu-6WiVSDaNttPJwb_0og",
        "index": ".kibana_task_manager"
      },
      {
        "type": "query_shard_exception",
        "reason": "failed to create query: {\n  \"bool\" : {\n    \"must\" : [\n      {\n        \"term\" : {\n          \"languageSkills.languageId\" : {\n            \"value\" : \"10\",\n            \"boost\" : 1.0\n          }\n        }\n      }\n    ],\n    \"must_not\" : [\n      {\n        \"term\" : {\n          \"RemoveFromPositions\" : {\n            \"value\" : \"12fv567a-1ede-2f0-a75a-d1d236dcb38f\",\n            \"boost\" : 1.0\n          }\n        }\n      },\n      {\n        \"nested\" : {\n          \"query\" : {\n            \"bool\" : {\n              \"must\" : [\n                {\n                  \"term\" : {\n                    \"positions.PositionID\" : {\n                      \"value\" : \"12fv567a-1ede-2f0-a75a-d1d236dcb38f\",\n                      \"boost\" : 1.0\n                    }\n                  }\n                }\n              ],\n              \"adjust_pure_negative\" : true,\n              \"boost\" : 1.0\n            }\n          },\n          \"path\" : \"positions\",\n          \"ignore_unmapped\" : false,\n          \"score_mode\" : \"avg\",\n          \"boost\" : 1.0\n        }\n      }\n    ],\n    \"adjust_pure_negative\" : true,\n    \"boost\" : 1.0\n  }\n}",
        "index_uuid": "AN6WIKyhSSicELb8AihmWw",
        "index": "My_Index_For_ES"
      },
      {
        "type": "query_shard_exception",
        "reason": "failed to create query: {\n  \"bool\" : {\n    \"must\" : [\n      {\n        \"term\" : {\n          \"languageSkills.languageId\" : {\n            \"value\" : \"10\",\n            \"boost\" : 1.0\n          }\n        }\n      }\n    ],\n    \"must_not\" : [\n      {\n        \"term\" : {\n          \"RemoveFromPositions\" : {\n            \"value\" : \"12fv567a-1ede-2f0-a75a-d1d236dcb38f\",\n            \"boost\" : 1.0\n          }\n        }\n      },\n      {\n        \"nested\" : {\n          \"query\" : {\n            \"bool\" : {\n              \"must\" : [\n                {\n                  \"term\" : {\n                    \"positions.PositionID\" : {\n                      \"value\" : \"12fv567a-1ede-2f0-a75a-d1d236dcb38f\",\n                      \"boost\" : 1.0\n                    }\n                  }\n                }\n              ],\n              \"adjust_pure_negative\" : true,\n              \"boost\" : 1.0\n            }\n          },\n          \"path\" : \"positions\",\n          \"ignore_unmapped\" : false,\n          \"score_mode\" : \"avg\",\n          \"boost\" : 1.0\n        }\n      }\n    ],\n    \"adjust_pure_negative\" : true,\n    \"boost\" : 1.0\n  }\n}",
        "index_uuid": "Ao-Ded1dVfgXZfydvUFpli",
        "index": "My_Index_For_ES2"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": ".kibana_1",
        "node": "dxDWdF4VFpu8jcqBk50W2W",
        "reason": {
          "type": "query_shard_exception",
          "reason": "failed to create query: {\n  \"bool\" : {\n    \"must\" : [\n      {\n        \"term\" : {\n          \"languageSkills.languageId\" : {\n            \"value\" : \"10\",\n            \"boost\" : 1.0\n          }\n        }\n      }\n    ],\n    \"must_not\" : [\n      {\n        \"term\" : {\n          \"RemoveFromPositions\" : {\n            \"value\" : \"12fv567a-1ede-2f0-a75a-d1d236dcb38f\",\n            \"boost\" : 1.0\n          }\n        }\n      },\n      {\n        \"nested\" : {\n          \"query\" : {\n            \"bool\" : {\n              \"must\" : [\n                {\n                  \"term\" : {\n                    \"positions.PositionID\" : {\n                      \"value\" : \"12fv567a-1ede-2f0-a75a-d1d236dcb38f\",\n                      \"boost\" : 1.0\n                    }\n                  }\n                }\n              ],\n              \"adjust_pure_negative\" : true,\n              \"boost\" : 1.0\n            }\n          },\n          \"path\" : \"positions\",\n          \"ignore_unmapped\" : false,\n          \"score_mode\" : \"avg\",\n          \"boost\" : 1.0\n        }\n      }\n    ],\n    \"adjust_pure_negative\" : true,\n    \"boost\" : 1.0\n  }\n}",
          "index_uuid": "eCFSSERoQ-a1jAW4_-ccJg",
          "index": ".kibana_1",
          "caused_by": {
            "type": "illegal_state_exception",
            "reason": "[nested] failed to find nested object under path [positions]"
          }
        }
      },
      {
        "shard": 0,
        "index": ".kibana_task_manager",
        "node": "dxDWdF4VFpu8jcqBk50W2W",
        "reason": {
          "type": "query_shard_exception",
          "reason": "failed to create query: {\n  \"bool\" : {\n    \"must\" : [\n      {\n        \"term\" : {\n          \"languageSkills.languageId\" : {\n            \"value\" : \"10\",\n            \"boost\" : 1.0\n          }\n        }\n      }\n    ],\n    \"must_not\" : [\n      {\n        \"term\" : {\n          \"RemoveFromPositions\" : {\n            \"value\" : \"12fv567a-1ede-2f0-a75a-d1d236dcb38f\",\n            \"boost\" : 1.0\n          }\n        }\n      },\n      {\n        \"nested\" : {\n          \"query\" : {\n            \"bool\" : {\n              \"must\" : [\n                {\n                  \"term\" : {\n                    \"positions.PositionID\" : {\n                      \"value\" : \"12fv567a-1ede-2f0-a75a-d1d236dcb38f\",\n                      \"boost\" : 1.0\n                    }\n                  }\n                }\n              ],\n              \"adjust_pure_negative\" : true,\n              \"boost\" : 1.0\n            }\n          },\n          \"path\" : \"positions\",\n          \"ignore_unmapped\" : false,\n          \"score_mode\" : \"avg\",\n          \"boost\" : 1.0\n        }\n      }\n    ],\n    \"adjust_pure_negative\" : true,\n    \"boost\" : 1.0\n  }\n}",
          "index_uuid": "ncu-6WiVSDaNttPJwb_0og",
          "index": ".kibana_task_manager",
          "caused_by": {
            "type": "illegal_state_exception",
            "reason": "[nested] failed to find nested object under path [positions]"
          }
        }
      },
      {
        "shard": 0,
        "index": "My_Index_For_ES",
        "node": "dxDWdF4VFpu8jcqBk50W2W",
        "reason": {
          "type": "query_shard_exception",
          "reason": "failed to create query: {\n  \"bool\" : {\n    \"must\" : [\n      {\n        \"term\" : {\n          \"languageSkills.languageId\" : {\n            \"value\" : \"10\",\n            \"boost\" : 1.0\n          }\n        }\n      }\n    ],\n    \"must_not\" : [\n      {\n        \"term\" : {\n          \"RemoveFromPositions\" : {\n            \"value\" : \"12fv567a-1ede-2f0-a75a-d1d236dcb38f\",\n            \"boost\" : 1.0\n          }\n        }\n      },\n      {\n        \"nested\" : {\n          \"query\" : {\n            \"bool\" : {\n              \"must\" : [\n                {\n                  \"term\" : {\n                    \"positions.PositionID\" : {\n                      \"value\" : \"12fv567a-1ede-2f0-a75a-d1d236dcb38f\",\n                      \"boost\" : 1.0\n                    }\n                  }\n                }\n              ],\n              \"adjust_pure_negative\" : true,\n              \"boost\" : 1.0\n            }\n          },\n          \"path\" : \"positions\",\n          \"ignore_unmapped\" : false,\n          \"score_mode\" : \"avg\",\n          \"boost\" : 1.0\n        }\n      }\n    ],\n    \"adjust_pure_negative\" : true,\n    \"boost\" : 1.0\n  }\n}",
          "index_uuid": "AN6WIKyhSSicELb8AihmWw",
          "index": "My_Index_For_ES",
          "caused_by": {
            "type": "illegal_state_exception",
            "reason": "[nested] nested object under path [positions] is not of nested type"
          }
        }
      },
      {
        "shard": 0,
        "index": "My_Index_For_ES2",
        "node": "dxDWdF4VFpu8jcqBk50W2W",
        "reason": {
          "type": "query_shard_exception",
          "reason": "failed to create query: {\n  \"bool\" : {\n    \"must\" : [\n      {\n        \"term\" : {\n          \"languageSkills.languageId\" : {\n            \"value\" : \"10\",\n            \"boost\" : 1.0\n          }\n        }\n      }\n    ],\n    \"must_not\" : [\n      {\n        \"term\" : {\n          \"RemoveFromPositions\" : {\n            \"value\" : \"12fv567a-1ede-2f0-a75a-d1d236dcb38f\",\n            \"boost\" : 1.0\n          }\n        }\n      },\n      {\n        \"nested\" : {\n          \"query\" : {\n            \"bool\" : {\n              \"must\" : [\n                {\n                  \"term\" : {\n                    \"positions.PositionID\" : {\n                      \"value\" : \"12fv567a-1ede-2f0-a75a-d1d236dcb38f\",\n                      \"boost\" : 1.0\n                    }\n                  }\n                }\n              ],\n              \"adjust_pure_negative\" : true,\n              \"boost\" : 1.0\n            }\n          },\n          \"path\" : \"positions\",\n          \"ignore_unmapped\" : false,\n          \"score_mode\" : \"avg\",\n          \"boost\" : 1.0\n        }\n      }\n    ],\n    \"adjust_pure_negative\" : true,\n    \"boost\" : 1.0\n  }\n}",
          "index_uuid": "Ao-Ded1dVfgXZfydvUFpli",
          "index": "My_Index_For_ES2",
          "caused_by": {
            "type": "illegal_state_exception",
            "reason": "[nested] nested object under path [positions] is not of nested type"
          }
        }
      }
    ]
  },
  "status": 400
}

Solution

  • Actually, you're querying all indices and the .kibana one doesn't have the fields you specify in your query.

    In general, you should prefer querying the exact set of indices you need, not only is your query going to be faster but you'll also get less errors like this one:

    GET <your_index_name>/_search
    

    Also note that the exact error says

    [nested] failed to find nested object under path [positions]

    which means that your positions field is not of type nested so you should simply remove the nested query and simply add this to your bool/must array

                  {
                    "term": {
                      "positions.PositionID": "Guid_Value_here"
                    }
                  }