gpt4 book ai didi

java - 如何使用 term_vector 在elasticsearch中索引新文档?

转载 作者:行者123 更新时间:2023-12-01 10:36:37 27 4
gpt4 key购买 nike

我正在尝试实现从 MongoDB 获取文档并将其插入 ElasticSearch 的应用程序。下面是一段应将文档插入 ElasticSearch 索引的代码:

final Document o = (Document) document.get("o"); // this is where object lives
client.prepareIndex(index, mapping, id.toString())
.setSource(o.toJson())
.execute().actionGet();

最后我得到了这个错误:

java.lang.IllegalArgumentException: Mapper for [title] conflicts with existing mapping in other types: [mapper [title] has different [store_term_vector] values, mapper [title] has different [store_term_vector_offsets] values, mapper [title] has different [store_term_vector_positions] values, mapper [title] has different [store_term_vector_payloads] values] at org.elasticsearch.index.mapper.FieldTypeLookup.checkCompatibility(FieldTypeLookup.java:117) at org.elasticsearch.index.mapper.MapperService.checkNewMappersCompatibility(MapperService.java:368) at org.elasticsearch.index.mapper.MapperService.merge(MapperService.java:319)

我尝试使用 XDELETE 完全删除索引并使用 XPUT 重新创建,但错误仍然存​​在。

这是我的索引设置:

{
"msg": {
"mappings": {
"Message": {
"properties": {
"title": {
"type": "string",
"term_vector": "with_positions_offsets_payloads",
"analyzer": "russian"
}
}
}
}
}
}

但是,如果我从索引设置中删除此 term_vector 部分,则代码将成功插入新文档。

谁能帮我解释一下这是什么问题吗?当我尝试使用 mongo-connector 时,也会出现同样的问题。如果 settings 包含 title 字段的 term_vector 部分 => mongo-connector 失败并出现相同的异常。而且在没有 term_vector 的情况下也能正常工作。

最佳答案

您确定使用了正确的 term_vector 值吗?我只知道该属性的五个有效值 as listed in the documentation :

Possible values are no, yes, with_offsets, with_positions, with_positions_offsets. Defaults to no.

我建议尝试不同的term_vector,例如with_positions_offsets,看看是否获得了预期的结果。

关于java - 如何使用 term_vector 在elasticsearch中索引新文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34680820/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com