Issue with create index with mapping

2019-08-16 02:24发布

问题:

I'm using elastic search version 7.1.0 and NEST 6.7.0 with Elasticsearch.Net 6.7.0. While I'm trying to create an index I've got an error.

This is my code, I was using the same code on NEST and Elasticsearch.Net version 6.4.0 and it was working fine

var result =   Client.CreateIndex(DefaultIndex, c => c
                .Settings(s => s
                    .NumberOfShards(numberOfShards)
                    .NumberOfReplicas(numberOfReplicas)
                    .BlocksReadOnly(false)
                )
                .Mappings(m => m
                    .Map<SearchDocument>(mm => mm
                        .AutoMap(3)
                    )
                )
            );

This is the error that I got

Invalid NEST response built from a unsuccessful low level call on PUT: /local_brainbank_index

Audit trail of this API call:

  • [1] BadResponse: Node: http://localhost:9200/ Took: 00:00:00.2880040

    OriginalException: Elasticsearch.Net.ElasticsearchClientException: The remote server returned an error: (400) Bad Request.. Call: Status

code 400 from: PUT /local_brainbank_index. ServerError: Type: mapper_parsing_exception Reason: "Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters: [searchdocument : {properties={sourceId={type=integer}, sourceType={type=text, fields={keyword={ignore_above=256, type=keyword}}}, authorName={type=text, fields={keyword={ignore_above=256, type=keyword}}}, subject={type=text, fields={keyword={ignore_above=256, type=keyword}}}, imageURL={type=text, fields={keyword={ignore_above=256, type=keyword}}}, id={type=text, fields={keyword={ignore_above=256, type=keyword}}}, sourceName={type=text, fields={keyword={ignore_above=256, type=keyword}}}, body={type=text, fields={keyword={ignore_above=256, type=keyword}}}, uRL={type=text, fields={keyword={ignore_above=256, type=keyword}}}}}]" CausedBy: "Type: mapper_parsing_exception Reason: "Root mapping definition has unsupported parameters: [searchdocument : {properties={sourceId={type=integer}, sourceType={type=text, fields={keyword={ignore_above=256, type=keyword}}}, authorName={type=text, fields={keyword={ignore_above=256, type=keyword}}}, subject={type=text, fields={keyword={ignore_above=256, type=keyword}}}, imageURL={type=text, fields={keyword={ignore_above=256, type=keyword}}}, id={type=text, fields={keyword={ignore_above=256, type=keyword}}}, sourceName={type=text, fields={keyword={ignore_above=256, type=keyword}}}, body={type=text, fields={keyword={ignore_above=256, type=keyword}}}, uRL={type=text, fields={keyword={ignore_above=256, type=keyword}}}}}]"" ---> System.Net.WebException: The remote server returned an error: (400) Bad Request. at System.Net.HttpWebRequest.GetResponse() at Elasticsearch.Net.HttpWebRequestConnection.Request[TResponse](RequestData requestData) --- End of inner exception stack trace ---

Request:

{"mappings":{"searchdocument":{"properties":{"id":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"sourceType":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"sourceId":{"type":"integer"},"sourceName":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"authorName":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"subject":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"body":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"uRL":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"imageURL":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}}},"settings":{"index.number_of_replicas":0,"index.blocks.read_only":false,"index.number_of_shards":1}}

Response:

{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters: [searchdocument : {properties={sourceId={type=integer}, sourceType={type=text, fields={keyword={ignore_above=256, type=keyword}}}, authorName={type=text, fields={keyword={ignore_above=256, type=keyword}}}, subject={type=text, fields={keyword={ignore_above=256, type=keyword}}}, imageURL={type=text, fields={keyword={ignore_above=256, type=keyword}}}, id={type=text, fields={keyword={ignore_above=256, type=keyword}}}, sourceName={type=text, fields={keyword={ignore_above=256, type=keyword}}}, body={type=text, fields={keyword={ignore_above=256, type=keyword}}}, uRL={type=text, fields={keyword={ignore_above=256, type=keyword}}}}}]"}],"type":"mapper_parsing_exception","reason":"Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters: [searchdocument : {properties={sourceId={type=integer}, sourceType={type=text, fields={keyword={ignore_above=256, type=keyword}}}, authorName={type=text, fields={keyword={ignore_above=256, type=keyword}}}, subject={type=text, fields={keyword={ignore_above=256, type=keyword}}}, imageURL={type=text, fields={keyword={ignore_above=256, type=keyword}}}, id={type=text, fields={keyword={ignore_above=256, type=keyword}}}, sourceName={type=text, fields={keyword={ignore_above=256, type=keyword}}}, body={type=text, fields={keyword={ignore_above=256, type=keyword}}}, uRL={type=text, fields={keyword={ignore_above=256, type=keyword}}}}}]","caused_by":{"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters: [searchdocument : {properties={sourceId={type=integer}, sourceType={type=text, fields={keyword={ignore_above=256, type=keyword}}}, authorName={type=text, fields={keyword={ignore_above=256, type=keyword}}}, subject={type=text, fields={keyword={ignore_above=256, type=keyword}}}, imageURL={type=text, fields={keyword={ignore_above=256, type=keyword}}}, id={type=text, fields={keyword={ignore_above=256, type=keyword}}}, sourceName={type=text, fields={keyword={ignore_above=256, type=keyword}}}, body={type=text, fields={keyword={ignore_above=256, type=keyword}}}, uRL={type=text, fields={keyword={ignore_above=256, type=keyword}}}}}]"}},"status":400}

回答1:

NEST and Elasticsearch.Net 6.7.0 are not compatible with Elasticsearch 7.x. Please use NEST and Elasticsearch.Net 7.x, the latest of which to be released is 7.0.0-alpha2 at this time.