Elasticsearch - 在 path_route 上找不到嵌套类型

Elasticsearch - Cannot find nested type on path_route

错误原因:java.lang.IllegalStateException:路径 [path_route] 下的 [nested] 嵌套对象不是嵌套类型。相同的代码在另一台电脑上完美运行。

GET content/_search
{
    "from": 0,
    "size": 0,
    "query": {
    "bool": {
        "must": [
            {
                "nested": {
                    "path": "path_route",
                    "query": {
                        "bool": {
                            "must": {
                                "terms": {
                                    "path_route.status": [
                                        "approved"
                                    ]
                                }
                            }
                        }
                    }
                }
            }

        ]

    }
}

}

此类错误信息并非虚构。您需要验证 path_route 确实属于 nested 类型。

运行 GET content/_mapping 并验证它看起来与此类似:

{
  "content": {
    "mappings": {
      "doc": {
        "properties": {
          "path_route": {
            "type": "nested",         <-------
            "properties": {
              "status": {
                "type": "text"
              }
            }
          }
        }
      }
    }
  }
}

如果不是,请指定:

PUT /content
{
  "mappings": {
    "doc": {
      "properties": {
        "path_route": {
          "type": "nested",
          "properties": {
            "status": {
              "type": "text"
            }
          }
        }
      }
    }
  }
}