【问题标题】:Create Index Request Mapping is failing in elastic search创建索引请求映射在弹性搜索中失败
【发布时间】:2020-10-09 06:58:02
【问题描述】:

我正在尝试在弹性搜索索引中创建 Join 数据类型,它正在从 kibana 控制台/通过 rest 工作,但是当我尝试以编程方式为索引创建映射时,它失败并出现以下错误,

java.util.concurrent.ExecutionException: RemoteTransportException[[3cfb4e163654][172.17.0.2:9300][indices:admin/create]]; nested: MapperParsingException[Failed to parse mapping [properties]: Root mapping definition has unsupported parameters:  [my_join_field : {type=join, relations={question=answer}}] [my_id : {type=keyword}]]; nested: MapperParsingException[Root mapping definition has unsupported parameters:  [my_join_field : {type=join, relations={question=answer}}] [my_id : {type=keyword}]];

映射:

{
    "properties": {
      "my_id": {
        "type": "keyword"
      },
      "my_join_field": { 
        "type": "join",
        "relations": {
          "question": "answer" 
        }
      }
    }
  }

代码:

public void createIndex(ReIndex indexObject) throws XXXDefinedException {
        String index = indexObject.getDestinationIndex();
        try {
            LOG.info("Initiating the index creation process for the " + index);
            CreateIndexRequest request = new CreateIndexRequest(index);
            if (!CommonUtils.isEmptyMap(indexObject.getMapping())) {
                LOG.info("Index Mapping Available : " + index);
                String indexMapping = new GsonBuilder().create().toJson(indexObject.getMapping());
                request.source(indexMapping, XContentType.JSON);
            }
            AcknowledgedResponse indexResponse = client.admin().indices().create(request).get();
            client.admin().indices().prepareRefresh().execute().actionGet();
            LOG.info("Index is created successfully : " + indexResponse);
        } catch (Exception e) {
            throw new XXXDefinedException (e);
        }
    }

其中 inputObject.getMapping() 具有以下映射:

  {"mappings":{"properties":{"my_id":{"type":"keyword"},"my_join_field":{"type":"join","relations":{"question":"answer"}}}}}

【问题讨论】:

  • 您也可以添加导入语句吗? indexObject 似乎有问题?

标签: java elasticsearch elasticsearch-7 resthighlevelclient


【解决方案1】:

您的inputObject.getMapping() 不应包含mapping 部分。您能否在 inputObject.getMapping() 中进行更改:

{"mappings":{"properties":{"my_id":{"type":"keyword"},"my_join_field":{"type":"join","relations":{"question":"answer"}}}}}

{"properties":{"my_id":{"type":"keyword"},"my_join_field":{"type":"join","relations":{"question":"answer"}}}}

让我知道这是否可行。

【讨论】:

  • 是的,但是弹性搜索在内部存储为映射 -> 映射 -> 属性,请检查此链接:所以我将 request.source 与 {"mappings":{"mappings":{"properties": {"my_id":{"type":"keyword"},"my_join_field":{"type":"join","re​​lations":{"question":"answer"}}}}}} 并且有效
  • 抱歉,我使用了 request.mapping(jsonString,XContentType.JSON); 方法,而不是您使用的方法,即 request.source(jsonString, XContenType.JSON);。我相信两者都应该足够正确,并且最终会转换为 elasticsearch 所需的正确 JSON 格式。如果您阅读CreateRequestIndex 的源代码,您将能够看到这两种方法是如何使用的。
  • 奇怪我已经尝试使用源方法和你拥有的映射字符串,但我仍然遇到问题。您能否更新 maven 详细信息,只想检查您使用的 ES 版本。我已经尝试过 7.7 和两次,只有我在答案中提到的 JSON 有效,但不是你在评论中提到的。
猜你喜欢
  • 2019-09-28
  • 1970-01-01
  • 1970-01-01
  • 2016-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-15
  • 1970-01-01
相关资源
最近更新 更多