弹性搜索,通过Rest Java客户端使用源和设置创建索引
我正试图按照以下指南创建索引:弹性搜索,通过Rest Java客户端使用源和设置创建索引,java,elasticsearch,Java,elasticsearch,我正试图按照以下指南创建索引: 问题是,该索引没有正确创建。看起来整个设置部分以及完成类型被忽略 我的json文件: { "settings": { "number_of_shards": 3, "number_of_replicas": 1, "analysis": { "filter": {}, "analyzer": { "keyword_analyzer
问题是,该索引没有正确创建。看起来整个
设置
部分以及完成
类型被忽略
我的json文件:
{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 1,
"analysis": {
"filter": {},
"analyzer": {
"keyword_analyzer": {
"filter": [
"lowercase",
"asciifolding",
"trim"
],
"char_filter": [],
"type": "custom",
"tokenizer": "keyword"
}
}
}
},
"mappings": {
"my_type": {
"properties": {
"first": {
"type": "text",
"fields": {
"keywordstring": {
"type": "text",
"analyzer": "keyword_analyzer"
},
"completion": {
"type": "completion"
}
},
"analyzer": "standard"
},
"second": {
"type": "text",
"fields": {
"keywordstring": {
"type": "text",
"analyzer": "keyword_analyzer"
},
"completion": {
"type": "completion"
}
},
"analyzer": "standard"
},
"third": {
"type": "text",
"fields": {
"keywordstring": {
"type": "text",
"analyzer": "keyword_analyzer"
},
"completion": {
"type": "completion"
}
},
"analyzer": "standard"
},
"fourth": {
"type": "text",
"fields": {
"keywordstring": {
"type": "text",
"analyzer": "keyword_analyzer"
},
"completion": {
"type": "completion"
}
},
"analyzer": "standard"
}
}
}
}
}
Java代码:
CreateIndexRequest indexRequest = new CreateIndexRequest(ESClientConfiguration.INDEX_NAME);
URL url = Resources.getResource(TERYT_INDEX_CONFIGURATION_FILE_NAME);
return Try.of(() -> Resources.toString(url, Charsets.UTF_8))
.map(jsonIndexConfiguration -> indexRequest.source(jsonIndexConfiguration, XContentType.JSON))
.get();
createIndexRequest.setTimeout(TimeValue.timeValueMinutes(2));
Try.of(() -> client.indices().create(createIndexRequest, RequestOptions.DEFAULT))...
索引已创建,但当我查看索引元数据时,它看起来完全错误:
{
"state": "open",
"settings": {
"index": {
"creation_date": "1556379012380",
"number_of_shards": "1",
"number_of_replicas": "1",
"uuid": "L5fmkrjeQ6eKmuDyZ3MP3g",
"version": {
"created": "7000099"
},
"provided_name": "my_index"
}
},
"mappings": {
"my_type": {
"properties": {
"first": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"second": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"third": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"fourth": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
}
}
}
},
"aliases": [],
"primary_terms": {
"0": 1
},
"in_sync_allocations": {
"0": [
"Cx6tBeohR8mzbTO74dwsCw",
"FcTUhpb_SL2LiaEyy_uwkg"
]
}
}
只有1个没有副本的碎片,我也看不到任何关于
completion
type的信息。有人能告诉我我做错了什么吗?我想这句话:
Try.of(() -> client.indices().create(createIndexRequest, RequestOptions.DEFAULT))...
隐藏一个重要的异常。
这里您使用的是elasticsearch 7.0.0,它不再允许在映射中提供“类型”名称
而不是
"mappings": {
"my_type": {
"properties": {
你应该写:
"mappings": {
"properties": {
由于该异常以及可能在创建索引之后为某些文档编制索引的事实,将应用默认索引设置和映射。
这就解释了你所看到的
您需要先修复索引设置。
我建议您在Kibana开发控制台中执行此操作。您的索引是否可能已经存在?否:/我现在删除了整个索引您是否发现任何异常?顺便问一下,那是哪个版本?没有例外,索引创建得很好,但设置错误。这是7.0.0版本,所以我可以告诉你,你的索引不是用那些索引设置创建的。我认为您正在运行的代码会创建文档,对吗?这些文档使用默认映射创建索引。再次检查您的代码。