繁体   English   中英

Elasticsearch:根映射定义具有不受支持的参数索引:not_analyzed

[英]Elasticsearch : Root mapping definition has unsupported parameters index : not_analyzed

大家好,我正在尝试创建模式测试。

PUT /test
{
    "mappings": {
        "field1": {
            "type": "integer"
        },
        "field2": {  
            "type": "integer"
        },
        "field3": {
            "type": "string",
            "index": "not_analyzed"
        },
        "field4": {
            "type": "string",
            "analyzer": "autocomplete",
            "search_analyzer": "standard"
        }
    },
    "settings": {
        bla
        bla
        bla
    }
}

我收到以下错误

{
    "error": {
        "root_cause": [{
            "type": "mapper_parsing_exception",
            "reason": "Root mapping definition has unsupported parameters: [index : not_analyzed] [type : string]"
        }],
        "type": "mapper_parsing_exception",
        "reason": "Failed to parse mapping [featured]: Root mapping definition has unsupported parameters:  [index : not_analyzed] [type : string]",
        "caused_by": {
            "type": "mapper_parsing_exception",
            "reason": "Root mapping definition has unsupported parameters:  [index : not_analyzed] [type : string]"
        }
    },
    "status": 400
}

请帮我解决这个错误

你快到了,你只是缺少一些东西:

PUT /test
{
  "mappings": {
    "type_name": {                <--- add the type name
      "properties": {             <--- enclose all field definitions in "properties"
        "field1": {
          "type": "integer"
        },
        "field2": {
          "type": "integer"
        },
        "field3": {
          "type": "string",
          "index": "not_analyzed"
        },
        "field4,": {
          "type": "string",
          "analyzer": "autocomplete",
          "search_analyzer": "standard"
        }
      }
    }
  },
  "settings": {
     ...
  }
}

更新

如果您的索引已经存在,您还可以像这样修改您的映射:

PUT test/_mapping/type_name
{
    "properties": {             <--- enclose all field definitions in "properties"
        "field1": {
          "type": "integer"
        },
        "field2": {
          "type": "integer"
        },
        "field3": {
          "type": "string",
          "index": "not_analyzed"
        },
        "field4,": {
          "type": "string",
          "analyzer": "autocomplete",
          "search_analyzer": "standard"
        }
    }
}

更新

从 ES 7 开始,映射类型已被删除。 您可以在此处阅读更多详细信息

我希望上述答案适用于弹性搜索 <7.0,但在 7.0 中我们无法指定文档类型,并且不再支持它。 在这种情况下,如果我们指定 doc 类型,我们会得到类似的错误。

我正在使用 Elastic search 7.0 和 Nest C# 最新版本 (6.6)。 ES 7.0 有一些重大变化导致了这个问题。 这是因为我们无法指定 doc 类型,并且在 NEST 6.6 版中他们使用的是 doctype。 所以为了解决这个问题,直到 NEST 7.0 发布,我们需要下载他们的测试包

请通过此链接进行修复

https://xyzcoder.github.io/elasticsearch/nest/2019/04/12/es-70-and-nest-mapping-error.html

编辑: NEST 7.0 现已发布。 NEST 7.0 与 Elastic 7.0 配合使用。 有关详细信息,请参阅此处发行说明

从 ES 7 开始,映射类型已被删除。 您可以在此处阅读更多详细信息

如果您使用 Ruby On Rails,这意味着您可能需要从模型或关注点中删除document_type

作为映射类型的替代方案,一种解决方案是对每个文档类型使用索引。

之前:

module Searchable
  extend ActiveSupport::Concern

  included do
    include Elasticsearch::Model
    include Elasticsearch::Model::Callbacks
    index_name [Rails.env, Rails.application.class.module_parent_name.underscore].join('_')
    document_type self.name.downcase
  end
end

之后:

module Searchable
  extend ActiveSupport::Concern

  included do
    include Elasticsearch::Model
    include Elasticsearch::Model::Callbacks
    index_name [Rails.env, Rails.application.class.module_parent_name.underscore, self.name.downcase].join('_')
  end
end

检查您的弹性版本。

我遇到这些问题是因为我查看了错误版本的文档。

在此处输入图片说明

我正在运行 Elastic Search 7.12 版

当我运行以下命令时

curl -H 'Content-Type: application/json' -XPUT 127.0.0.1:9200/movies?pretty -d '
{
    "mappings" : {
        "movie": {
            "properties" : {
                "year" : { "type": "date" }
            }
        }
    }   
}'

返回以下错误。

{
  "error" : {
    "root_cause" : [
      {
        "type" : "mapper_parsing_exception",
        "reason" : "Root mapping definition has unsupported parameters:  [movie : {properties={year={type=date}}}]"
      }
    ],
    "type" : "mapper_parsing_exception",
    "reason" : "Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters:  [movie : {properties={year={type=date}}}]",
    "caused_by" : {
      "type" : "mapper_parsing_exception",
      "reason" : "Root mapping definition has unsupported parameters:  [movie : {properties={year={type=date}}}]"
    }
  },
  "status" : 400
}

为了缓解这种情况,请按如下方式修改查询中的 json。

curl -H 'Content-Type: application/json' -XPUT 127.0.0.1:9200/movies?pretty -d '
{
    "mappings" : {
        "properties" : {
            "year" : { "type": "date" }
        }
    }   
}'

注意:删除了“电影”:{} 层。 现在它起作用了。

PUT /testIndex
{
    "mappings": {
        "properties": {     <--ADD THIS
            "field1": {
                "type": "integer"
            },
            "field2": {  
                "type": "integer"
            },
            "field3": {
                "type": "string",
                "index": "not_analyzed"
            },
            "field4": {
                "type": "string",
                "analyzer": "autocomplete",
                "search_analyzer": "standard"
            }
        }
    },
    "settings": {
        bla
        bla
        bla
    }
}

这是我知道有效的类似命令:

curl -v -H "Content-Type: application/json" -H "Authorization: Basic cGC3COJ1c2Vy925hZGFJbXBvcnABCnRl" -X PUT -d '{"mappings":{"properties":{"city":{"type": "text"}}}}' https://35.80.2.21/manzanaIndex

上述 curl 命令的细分是:

PUT /manzanaIndex
{
    "mappings":{
        "properties":{
                "city":{
                    "type": "text"
                }
        }
    }
}

如果您在 Python 中使用elasticsearch_dsl ,此错误可能只是意味着您没有使用正确版本的库。

库版本对应于 Elasticsearch 版本。

所以如果你使用 Elasticsearch 7.x ,elasticsearch_dsl 应该是7.x等等

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM