简体   繁体   中英

Getting below error in elastic search rest high level client

I am getting below error when i try to create the mapping using create index request.

Elasticsearch exception [type=mapper_parsing_exception, reason=Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters: [recommendations: {recommendations={properties={events={type=nested, properties={recommendationData={type=nested, properties={recommendations={type=nested, properties={recommendationType={type=keyword}}}}}}}}}}]]

and the mapping is

{
  "mappings": {
    "recommendations": {
      "properties": {
        "events": {
          "type": "nested",
          "properties": {
            "recommendationData": {
              "type": "nested",
              "properties": {
                "recommendations": {
                  "type": "nested",
                  "properties": {
                    "recommendationType": {
                      "type": "keyword"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

and the java code is

private void checkAndCreateDocumentMapping() throws IOException {

        CreateIndexRequest createIndexRequest = new CreateIndexRequest(this.getIndexName());
        String indexString = getStringFromFile("nested" + ".mapping");
        createIndexRequest.source(indexString, XContentType.JSON);
        client.indices().create(createIndexRequest, RequestOptions.DEFAULT);
    }

Please note that elasticsearch no more support multiple mappings therefore it is no more required to pass mapping name. Assuming recommendations is name of mapping, it can be instead used as name of index. Therefore correct dsl to create index should be,

PUT recommendations
{
  "mappings": {
    "properties": {
      "events": {
        "type": "nested",
        "properties": {
          "recommendationData": {
            "type": "nested",
            "properties": {
              "recommendations": {
                "type": "nested",
                "properties": {
                  "recommendationType": {
                    "type": "keyword"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM