Elasticsearch:根Map定义具有不支持的参数索引:未分析

llmtgqce  于 2023-06-29  发布在  ElasticSearch
关注(0)|答案(8)|浏览(137)

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

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
}

请帮助我解决此错误

z8dt9xmd

z8dt9xmd1#

你就快到了,你还差几样东西:

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": {
     ...
  }
}

更新

如果你的索引已经存在,你也可以像这样修改你的Map:

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开始,Map类型被删除了.您可以阅读更多详情here

cvxl0en2

cvxl0en22#

我希望以上答案适用于<7.0的ElasticSearch,但在7.0中,我们不能指定文档类型,并且不再支持。在这种情况下,如果我们指定文档类型,我们会得到类似的错误。
如果你正在使用Elastic search 7.0和Nest C#最新版本(6.6)。ES 7.0中有一些重大更改导致了此问题。这是因为我们不能指定文档类型,而在版本6.6的NEST中,他们使用的是doctype。因此,为了解决这个问题,直到NEST7.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兼容。详情请参阅release notes here

00jrzges

00jrzges3#

检查您的Elastic版本。
我有这些问题,因为我正在寻找不正确的版本的文档。

uubf1zoe

uubf1zoe4#

从ES 7开始,Map类型被删除了.您可以阅读更多详情here
如果您使用的是Ruby On Rails,这意味着您可能需要从模型或关注点中删除document_type
作为Map类型的替代方案,一种解决方案是对每个文档类型使用索引。
之前:

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
omhiaaxx

omhiaaxx5#

我正在运行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" }
        }
    }   
}'

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

wrrgggsh

wrrgggsh6#

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"
                }
        }
    }
}
1yjd4xko

1yjd4xko7#

如果你在Python中使用elasticsearch_dsl,这个错误可能只是意味着你没有使用正确版本的库。
库版本对应于Elasticsearch版本。
所以如果你使用的是Elasticsearch 7.x,elasticsearch_dsl应该是7.x,以此类推

vd2z7a6w

vd2z7a6w8#

如果你使用的是Python,你也可以使用requests库:
POST_URL = '<kibana_instance>/index_name/type_name/'
postdata = 'content_in_json_file.json'

response = requests.request("POST", POST_URL, data=postdata, headers={'Content-Type': 'application/octet-stream'})

检查状态和返回,看看是否一切正常:

response.status_code

response.content

相关问题