愚者求师之过,智者从师之长。

java如何创建父子关系索引时如何指定type,报错创建不了

Elasticsearch | 作者 ddys | 发布于2018年05月03日 | 阅读数:5615

在使用java创建索引,然后在注入父子关系的mapping的时候报错了,type怎么指定都是错的,代码如下:

1.png


2.png

 


 
已邀请:

JackGe

赞同来自: CarrieJin ddys

先使用json字符串在sense上测试下,例如
{
      "indexB": {
        "_routing": {
          "required": true
        },
        "_ttl": {
          "enabled": false
        },
        "properties": {
          "filedB": {
            "index": "not_analyzed",
            "type": "string"
          }
        },
        "_all": {
          "enabled": false
        },
        "_parent": {
          "type": "indexA"
        }
      },
      "indexA": {
        "_ttl": {
          "enabled": false
        },
        "properties": {
          "filedA": {
            "index": "not_analyzed",
            "type": "string"
          }
        },
        "_all": {
          "enabled": false
        }
      }
    }
然后在代码中mappings打印出来,例如
String esMapping = JsonXContent.contentBuilder().startObject().startObject("indexB").startObject("_routing").field("required", true).endObject() .startObject("_parent").field("type", "indexA").endObject().startObject("_all").field("enable", false).endObject() .startObject("indexA").startObject("_all").field("enable", false).endObject().endObject().string();
 

ddys

赞同来自:

错误是:Exception in thread "main" org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: mapping type is missing;  但是我指定type的话,又会提示我子类型还有一个type,还是创建不了

要回复问题请先登录注册