【问题标题】:Issue with create index with mapping使用映射创建索引的问题
【发布时间】:2019-05-22 14:00:52
【问题描述】:

我将 Elasticsearch 版本 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)
                    )
                )
            );

这是我得到的错误

从对 PUT 的不成功的低级别调用构建的无效 NEST 响应: /local_brainbank_index

此 API 调用的审计跟踪:

  • [1] 错误响应:节点:http://localhost:9200/ 接受:00:00:00.2880040

    OriginalException: Elasticsearch.Net.ElasticsearchClientException: 远程服务器返回错误:(400) Bad Request.. Call: Status

代码 400 来自:PUT /local_brainbank_index。服务器错误:类型: mapper_parsing_exception 原因:“无法解析映射 [_doc]:根 映射定义具有不受支持的参数:[searchdocument: {properties={sourceId={type=integer}, sourceType={type=text, 字段={关键字={ignore_above=256,类型=关键字}}}, authorName={type=text, fields={keyword={ignore_above=256, 类型=关键字}}},主题={类型=文本, 字段={关键字={ignore_above=256,类型=关键字}}}, imageURL={type=text, fields={keyword={ignore_above=256, type=keyword}}},id={type=text,fields={keyword={ignore_above=256, 类型=关键字}}},来源名称={类型=文本, 字段={关键字={ignore_above=256,类型=关键字}}},正文={类型=文本, 字段={关键字={ignore_above=256,类型=关键字}}},uRL={类型=文本, fields={keyword={ignore_above=256, type=keyword}}}}}]" "类型:mapper_parsing_exception 原因:"根映射定义有 不支持的参数:[搜索文档: {properties={sourceId={type=integer}, sourceType={type=text, 字段={关键字={ignore_above=256,类型=关键字}}}, authorName={type=text, fields={keyword={ignore_above=256, 类型=关键字}}},主题={类型=文本, 字段={关键字={ignore_above=256,类型=关键字}}}, imageURL={type=text, fields={keyword={ignore_above=256, type=keyword}}},id={type=text,fields={keyword={ignore_above=256, 类型=关键字}}},来源名称={类型=文本, 字段={关键字={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}}

回应:

{"error":{"root_cause":[{"type":"mapper_parsing_exception","re​​ason":"Root 映射定义具有不受支持的参数:[searchdocument: {properties={sourceId={type=integer}, sourceType={type=text, 字段={关键字={ignore_above=256,类型=关键字}}}, authorName={type=text, fields={keyword={ignore_above=256, 类型=关键字}}},主题={类型=文本, 字段={关键字={ignore_above=256,类型=关键字}}}, imageURL={type=text, fields={keyword={ignore_above=256, type=keyword}}},id={type=text,fields={keyword={ignore_above=256, 类型=关键字}}},来源名称={类型=文本, 字段={关键字={ignore_above=256,类型=关键字}}},正文={类型=文本, 字段={关键字={ignore_above=256,类型=关键字}}},uRL={类型=文本, 字段={关键字={ignore_above=256, type=keyword}}}}}]"}],"type":"mapper_parsing_exception","re​​ason":"失败 解析映射 [_doc]:根映射定义不受支持 参数:[搜索文档:{properties={sourceId={type=integer}, sourceType={type=text, fields={keyword={ignore_above=256, 类型=关键字}}},作者姓名={类型=文本, 字段={关键字={ignore_above=256,类型=关键字}}}, 主题={类型=文本,字段={关键字={ignore_above=256, 类型=关键字}}},imageURL={类型=文本, 字段={关键字={ignore_above=256,类型=关键字}}},id={类型=文本, 字段={关键字={ignore_above=256,类型=关键字}}}, sourceName={type=text, fields={keyword={ignore_above=256, 类型=关键字}}},正文={类型=文本,字段={关键字={ignore_above=256, type=keyword}}}, uRL={type=text, fields={keyword={ignore_above=256, type=keyword}}}}}]","caused_by":{"type":"mapper_parsing_exception","re​​ason":"Root 映射定义具有不受支持的参数:[searchdocument: {properties={sourceId={type=integer}, sourceType={type=text, 字段={关键字={ignore_above=256,类型=关键字}}}, authorName={type=text, fields={keyword={ignore_above=256, 类型=关键字}}},主题={类型=文本, 字段={关键字={ignore_above=256,类型=关键字}}}, imageURL={type=text, fields={keyword={ignore_above=256, type=keyword}}},id={type=text,fields={keyword={ignore_above=256, 类型=关键字}}},来源名称={类型=文本, 字段={关键字={ignore_above=256,类型=关键字}}},正文={类型=文本, 字段={关键字={ignore_above=256,类型=关键字}}},uRL={类型=文本, fields={keyword={ignore_above=256, type=keyword}}}}}]"}},"status":400}

【问题讨论】:

  • 7.x 版中的 Elasticsearch 与 7.x 版中的 NEST 搭配使用效果最佳。
  • @Rob NEST 没有 7.x 版本。最新版本是 6.7.0。我正在使用的
  • 有,但在 alpha 版本中。您需要在 nuget 管理器中选中“允许预发布”复选框(或下拉菜单)。 i.stack.imgur.com/YFlp5.jpg
  • 一行:使用安装的 ElasticSearch 的版本号更新 ElasticSearch.NET。

标签: c# elasticsearch nest elasticsearch.net


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-23
    • 2018-06-10
    • 2013-09-08
    • 2014-04-15
    • 1970-01-01
    • 2018-11-08
    相关资源
    最近更新 更多