我的API版本是6.3,我尝试创建索引。失败表明";映射定义不能嵌套在类型[_doc]下,除非include_type_name设置为true。这是我的代码:
CreateIndexRequest indexRequest = new CreateIndexRequest("user");
request.source("{n" +
" "settings" : {n" +
" "number_of_shards" : 1,n" +
" "number_of_replicas" : 0n" +
" },n" +
" "mappings" : {n" +
" "_doc" : {n" +
" "properties" : {n" +
" "message" : { "type" : "text" }n" +
" }n" +
" }n" +
" },n" +
" "aliases" : {n" +
" "twitter_alias" : {}n" +
" }n" +
"}", XContentType.JSON);
CreateIndexResponse createIndexResponse = restHighLevelClient.indices().create(indexRequest);
在我去除"_doc";如下,failure说";无法分析映射[_doc]:没有为字段[properties]"指定类型;。那么我现在该怎么办呢?
request.source("{n" +
" "settings" : {n" +
" "number_of_shards" : 1,n" +
" "number_of_replicas" : 0n" +
" },n" +
" "mappings" : {n" +
"
" "properties" : {n" +
" "message" : { "type" : "text" }n" +
" }n" +
"
" },n" +
" "aliases" : {n" +
" "twitter_alias" : {}n" +
" }n" +
"}", XContentType.JSON);
_doc
是一个临时类型名称,为了向后兼容而保留,为了准备删除它,请参阅删除类型以了解更多详细信息。
另请参阅时间表以及如何在您的版本上处理此突破性更改
- 在6.x中创建的索引只允许每个索引有一个类型。任何名称可以用于类型,但只能有一个。首选类型名称为_doc,因此索引API与它们具有相同的路径将在7.0中具有:PUT{index}/doc/{id}和POST{index}/doc
另请参阅https://www.elastic.co/guide/en/elasticsearch/reference/7.x/removal-of-types.html#_migrating_multi_type_indices_to_single_type本节介绍了如何在6.X.中使用它
我建议首先尝试使用REST API创建一个索引,看看include_type_name
和index.mapping.single_type
的组合是否有效,并相应地将其添加到代码中。
原因是一个映射API查询。我修正如下。
# ES6
PUT myindex
{
"settings": {
"number_of_shards": 5,
"number_of_replicas": 2
},
"mappings": {
"_doc": { <--------- Delete this layer
"properties": {
"blahblah": {
# ES7
PUT myindex
{
"settings": {
"number_of_shards": 5,
"number_of_replicas": 2
},
"mappings": {
"properties": {
"blahblah": {