带有映射的创建索引问题

时间:2019-05-22 14:00:52

标签: c# elasticsearch nest elasticsearch.net

我正在将Elastic search版本7.1.0和NEST 6.7.0与Elasticsearch.Net 6.7.0一起使用。 在尝试创建索引时,出现错误。

这是我的代码,我在NEST和Elasticsearch.Net 6.4.0版本上使用了相同的代码,并且运行正常

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)
                    )
                )
            );

这是我得到的错误

  

从上把一个不成功的低电平呼叫建立无效NEST响应:   / local_brainbank_index

     

此API调用的审核记录:

     
      
  • [1]错误响应:节点:http://localhost:9200/参加了:00:00:00.2880040      

    OriginalException:Elasticsearch.Net.ElasticsearchClientException:远程服务器返回错误:(400)错误的请求。。呼叫:状态

  •   
     

代码400,来自:PUT / local_brainbank_index。 ServerError:类型:   mapper_parsing_exception原因:“无法解析映射[_doc]:根   映射定义包含不受支持的参数:[searchdocument:   {properties = {sourceId = {type = integer},sourceType = {type = text,   字段= {关键字= {ignore_above = 256,类型=关键字}}},   authorName = {type = text,字段= {keyword = {ignore_above = 256,   type = keyword}}},subject = {type = text,   字段= {关键字= {ignore_above = 256,类型=关键字}}},   imageURL = {类型=文字,字段= {关键字= {ignore_above = 256,   type = keyword}}},id = {type = text,fields = {keyword = {ignore_above = 256,   type = keyword}}},sourceName = {type = text,   字段= {关键字= {ignore_above = 256,类型=关键字}}},正文= {类型=文字,   字段= {关键字= {ignore_above = 256,类型=关键字}}},uRL = {类型=文本,   field = {keyword = {ignore_above = 256,type = keyword}}}}}]“ CausedBy:   “类型:mapper_parsing_exception原因:”根映射定义具有   不支持的参数:[searchdocument:   {properties = {sourceId = {type = integer},sourceType = {type = text,   字段= {关键字= {ignore_above = 256,类型=关键字}}},   authorName = {type = text,字段= {keyword = {ignore_above = 256,   type = keyword}}},subject = {type = text,   字段= {关键字= {ignore_above = 256,类型=关键字}}},   imageURL = {类型=文字,字段= {关键字= {ignore_above = 256,   type = keyword}}},id = {type = text,fields = {keyword = {ignore_above = 256,   type = keyword}}},sourceName = {type = text,   字段= {关键字= {ignore_above = 256,类型=关键字}}},正文= {类型=文字,   字段= {关键字= {ignore_above = 256,类型=关键字}}},uRL = {类型=文本,   字段= {关键字= {ignore_above = 256,类型=关键字}}}}}]“” --->   System.Net.WebException:远程服务器返回错误:(400)   错误的请求。在System.Net.HttpWebRequest.GetResponse()在   Elasticsearch.Net.HttpWebRequestConnection.Request [TResponse](RequestData   requestData)---内部异常堆栈跟踪的结尾---

请求:

{"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}}

响应:

  

{“错误”:{“ root_cause”:[{“类型”:“ mapper_parsing_exception”,“原因”:“根   映射定义包含不受支持的参数:[searchdocument:   {properties = {sourceId = {type = integer},sourceType = {type = text,   字段= {关键字= {ignore_above = 256,类型=关键字}}},   authorName = {type = text,字段= {keyword = {ignore_above = 256,   type = keyword}}},subject = {type = text,   字段= {关键字= {ignore_above = 256,类型=关键字}}},   imageURL = {类型=文字,字段= {关键字= {ignore_above = 256,   type = keyword}}},id = {type = text,fields = {keyword = {ignore_above = 256,   type = keyword}}},sourceName = {type = text,   字段= {关键字= {ignore_above = 256,类型=关键字}}},正文= {类型=文字,   字段= {关键字= {ignore_above = 256,类型=关键字}}},uRL = {类型=文本,   字段= {关键字= {ignore_above = 256,   type = keyword}}}}}]“}]”,“ type”:“ mapper_parsing_exception”,“原因”:“失败   解析映射[_doc]:根映射定义不受支持   参数:[searchdocument:{properties = {sourceId = {type = integer},   sourceType = {类型=文本,字段= {关键字= {ignore_above = 256,   type = keyword}}},authorName = {type = text,   字段= {关键字= {ignore_above = 256,类型=关键字}}},   主题= {类型=文本,字段= {关键字= {ignore_above = 256,   type = keyword}}},imageURL = {type = text,   字段= {关键字= {ignore_above = 256,类型=关键字}}},id = {类型=文本,   字段= {关键字= {ignore_above = 256,类型=关键字}}},   sourceName = {类型=文本,字段= {关键字= {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”,“原因”:“ Root   映射定义包含不受支持的参数:[searchdocument:   {properties = {sourceId = {type = integer},sourceType = {type = text,   字段= {关键字= {ignore_above = 256,类型=关键字}}},   authorName = {type = text,字段= {keyword = {ignore_above = 256,   type = keyword}}},subject = {type = text,   字段= {关键字= {ignore_above = 256,类型=关键字}}},   imageURL = {类型=文字,字段= {关键字= {ignore_above = 256,   type = keyword}}},id = {type = text,fields = {keyword = {ignore_above = 256,   type = keyword}}},sourceName = {type = text,   字段= {关键字= {ignore_above = 256,类型=关键字}}},正文= {类型=文字,   字段= {关键字= {ignore_above = 256,类型=关键字}}},uRL = {类型=文本,   字段= {关键字= {ignore_above = 256,类型=关键字}}}}}]}},“状态”:400}

2 个答案:

答案 0 :(得分:0)

我可能是错的,但据我记得在第7版中没有文档类型。

Elasticsearch 7.x
Specifying types in requests is deprecated. For instance, indexing a document no longer requires a document type. The new index APIs are PUT {index}/_doc/{id} in case of explicit ids and POST {index}/_doc for auto-generated ids. Note that in 7.0, _doc is a permanent part of the path, and represents the endpoint name rather than the document type.
The include_type_name parameter in the index creation, index template, and mapping APIs will default to false. Setting the parameter at all will result in a deprecation warning.
The _default_ mapping type is removed.

所以,您可能需要解决的问题是更新映射。您可以调整ConnectionSettings

    public void Configure(ConnectionSettings connectionSettings)
    {
        connectionSettings
            .DefaultMappingFor<User>(m => m
                .TypeName("_doc")
                .IndexName(_esConfig.CustomerIndexPattern)
                .IdProperty(p => p.Id)
            )

或此document指出您可能可以使用

[ElasticsearchType(Name = "_doc")]属性

答案 1 :(得分:0)

NEST和Elasticsearch.Net 6.7.0与Elasticsearch 7.x不兼容。请使用NEST和Elasticsearch.Net 7.x,当前最新发布的是7.0.0-alpha2