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


79

大家好,我正在尝试创建架构测试。

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
}

请帮助我解决此错误

Answers:


118

您快到这里了,只是缺少了一些东西:

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开始,已删除映射类型。您可以在这里阅读更多详细信息


谢谢 。是否可以创建没有typename的映射。我想插入没有类型名称的数据,例如{field1,field2 ....},而不是typeName {field1,field2 ...}
Ramesh

1
好的,这是什么测试,什么是type_name?
拉梅什(Ramesh)2016年

6
test是您的索引名称,type_name也是您的映射类型的名称。
2016年

2
复制粘贴此代码。它给出了错误:“ type”:“ mapper_parsing_exception”,“ reason”:“根映射定义具有不受支持的参数:[type_name:{properties = {field1 = {type = integer},field4,= {search_analyzer = standard,Analyzer = autocomplete ,type = string},field3 = {index = not_analyzed,type = string},field2 = {type = integer}}}]“”
Ramesh Pareek

1
对我来说,这type_name是行不通的。我使用的是elasticsearch-oss:7.20码头图片
Sebastialonso,

19

我希望以上答案适用于<7.0的弹性搜索,但是在7.0中,我们无法指定doc类型,因此不再支持。在这种情况下,如果我们指定doc type,则会得到类似的错误。

我正在使用Elastic search 7.0和Nest C#最新版本(6.6)。ES 7.0的某些重大更改导致了此问题。这是因为我们无法指定文件类型,而在NEST的6.6版中,他们使用的是文件类型。因此,为了解决在发布NEST 7.0之前,我们需要下载其Beta版软件包

请通过此链接进行修复

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一起使用。有关详细信息,请参见此处发行说明


7

检查您的弹性版本。

我遇到了这些问题,因为我正在查看不正确的版本的文档。

在此处输入图片说明


3

从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

正是我的问题!很高兴在花了2个小时阅读文档后,这是一个简单的修复。
bkunzi01

0
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"
                }
        }
    }
}
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.