gpt4 book ai didi

elasticsearch - 使用 Transport Client 创建索引时,我应该如何将字段的分析指定为 not_analyzed

转载 作者:行者123 更新时间:2023-11-29 02:53:48 26 4
gpt4 key购买 nike

我正在使用 elasticsearch-6.1.1。由于 CreateIndexRequest api 不是由 JavaHighLeve client-6.1.1 提供的,我尝试通过使用此处给出的 TransportClient 来创建索引:( https://www.elastic.co/guide/en/elasticsearch/client/java-rest/master/_changing_the_application_8217_s_code.html )代码是:

public class IndexOperations {

RestHighLevelClient client ;
public IndexOperations(RestHighLevelClient client){
this.client = client ;
}

public void indexOperations()throws UnknownHostException,IOException {

TransportClient transportClient = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"),9300));


String mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("delllogfiles")
.startObject("properties")

.startObject("message")
.field("type","text")
.field("index","not_analyzed")
.endObject()

.startObject("logid")
.field("type","long")
.endObject()

.startObject("version")
.field("type","long")
.endObject()

.startObject("qualifiers")
.field("type","text")
.endObject()

.startObject("level")
.field("type","long")
.endObject()

.startObject("task")
.field("type","long")
.endObject()

.startObject("opcode")
.field("type","long")
.endObject()

.startObject("keywords")
.field("type","text")
.field("index","not_analyzed")
.endObject()

.startObject("recordid")
.field("type","long")
.endObject()

.startObject("providername")
.field("type","text")
.field("index","not_analyzed")
.endObject()

.startObject("providerid")
.field("type","long")
.endObject()

.startObject("logname")
.field("type","text")
.field("index","not_analyzed")
.endObject()

.startObject("processid")
.field("type","long")
.endObject()

.startObject("threadid")
.field("type","long")
.endObject()

.startObject("machinename")
.field("type","text")
.field("index","not_analyzed")
.endObject()

.startObject("userid")
.field("type","text")
.field("index","not_analyzed")
.endObject()

.startObject("timecreated")
.field("type","date")
.endObject()

.startObject("activityid")
.field("type","text")
.field("index","not_analyzed")
.endObject()

.startObject("relatedactivityid")
.field("type","text")
.field("index","not_analyzed")
.endObject()

.startObject("containerlog")
.field("type","text")
.field("index","not_analyzed")
.endObject()

.startObject("matchedqueryids")
.field("type","text")
.field("index","not_analyzed")
.endObject()

.startObject("bookmark")
.field("type","text")
.field("index","not_analyzed")
.endObject()

.startObject("levldispalyname")
.field("type","text")
.field("index","not_analyzed")
.endObject()

.startObject("opcodedisplayname")
.field("type","text")
.field("index","not_analyzed")
.endObject()

.startObject("taskdisplayname")
.field("type","text")
.field("index","not_analyzed")
.endObject()

.startObject("keywordsdisplayname")
.field("type","text")
.field("index","not_analyzed")
.endObject()

.startObject("properties")
.field("type","text")
.field("index","not_analyzed")
.endObject()

.endObject()
.endObject()
.endObject()
.string();


CreateIndexResponse createIndexResponse = transportClient.admin().indices()
.prepareCreate("logfiles")
.addMapping("delllogfiles",mapping,XContentType.JSON)
.get();

System.out.println("finally index created "+createIndexResponse.isAcknowledged());
transportClient.close();

当运行代码时,我得到一个异常:

Exception in thread "main" MapperParsingException[Failed to parse mapping [delllogfiless]: Could not convert [message.index] to boolean]; nested: IllegalArgumentException[Could not convert [message.index] to boolean]; nested: IllegalArgumentException[Failed to parse value [not_analyzed] as only [true] or [false] are allowed.];

如何在使用 TransportClient 时将字段的分析器设置为 not_analyzed?

最佳答案

来自elastic search 5的索引属性只有两个选项

  • 正确
  • 错误

对于 not_analyzed 字符串字段,使用字段类型 keyword 而不是默认为 not_analyzed 的 text

这是它的链接。 https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html

关于elasticsearch - 使用 Transport Client 创建索引时,我应该如何将字段的分析指定为 not_analyzed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48472963/

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