首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用弹性搜索6.1.1的mapper_parsing_exception

使用弹性搜索6.1.1的mapper_parsing_exception
EN

Stack Overflow用户
提问于 2019-06-02 23:07:36
回答 2查看 192关注 0票数 0

我正在尝试运行以下代码,并获取“mapper_parsing_exception”异常。此示例取自Elasticsearch 6.1.1的文档

代码语言:javascript
复制
from elasticsearch import Elasticsearch
import logging
import sys

logger = logging.getLogger(__name__)
es_host = {'host': 'localhost', 'port': 9200}
elastic_con = Elasticsearch(hosts=[es_host])

mapping = '''
{
    "mappings": {
        "article": {
            "properties": {
                "id": { "type": "text" },
                "title":  { "type": "text"},
                "abstract": { "type": "text"},
                "author": {
                    "properties": {
                        "id": { "type": "text" },
                        "name": { "type": "text" }
                    }
                }
            }
        }
    }
}
'''
res = elastic_con.indices.create(index='test-index', ignore=400, body=mapping)

if 'error' in res and res['status'] == 400:
    # NOTE: Illegal argument errors are also being masked here, so test the index creation
    error_type = res['error']['root_cause'][0]['type']
    if error_type == 'resource_already_exists_exception':
        logger.debug("Index already exists")
    else:
        logger.error("Error Occurred in Index creation:{0}".format(res))
        print("\n -- Unable to create Index:"+error_type+"--\n")
        sys.exit(1)
elif res['acknowledged'] and res['index'] == __index_name__:
    logger.debug("Index Created")
else:
    logger.error("Index creation failed:{0}".format(res))
    print("\n -- Unable to create Index--\n")
    sys.exit(1)

错误如下:

代码语言:javascript
复制
{
    "error":
        {"root_cause":[{
            "type":"mapper_parsing_exception",
            "reason":"Root mapping definition has unsupported parameters:  [article : {properties={author={properties={name={type=text}, id={type=text}}}, id={type=text}, abstract={type=text}, title={type=text}}}]"}],
        "type":"mapper_parsing_exception",
        "reason":"Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters:  [article : {properties={author={properties={name={type=text}, id={type=text}}}, id={type=text}, abstract={type=text}, title={type=text}}}]",
        "caused_by":{"type":"mapper_parsing_exception",
        "reason":"Root mapping definition has unsupported parameters:  [article : {properties={author={properties={name={type=text}, id={type=text}}}, id={type=text}, abstract={type=text}, title={type=text}}}]"}
        },
    "status":400
}

任何帮助都将不胜感激!:D

EN

回答 2

Stack Overflow用户

发布于 2019-06-03 00:47:44

如果你的属性中的任何字段是一个对象,就像这里的“作者”,那么你必须在你的映射中使用"type“:”嵌套“,如下所示……

代码语言:javascript
复制
mapping = '''
{
    "mappings": {
        "article": {
            "properties": {
                "id": { "type": "text" },
                "title":  { "type": "text"},
                "abstract": { "type": "text"},
                "author": {
                    "type": "nested",
                    "properties": {
                        "id": { "type": "text" },
                        "name": { "type": "text" }
                    }
                }
            }
        }
    }
}
'''
票数 0
EN

Stack Overflow用户

发布于 2019-06-03 13:45:48

您使用的是elasticsearch 7.x版,该版本不再支持type。因此,从映射中删除article并按如下方式使用:

代码语言:javascript
复制
{
  "mappings": {
    "properties": {
      "id": {
        "type": "text"
      },
      "title": {
        "type": "text"
      },
      "abstract": {
        "type": "text"
      },
      "author": {
        "properties": {
          "id": {
            "type": "text"
          },
          "name": {
            "type": "text"
          }
        }
      }
    }
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56416248

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档