【问题标题】:How to create a mutlitype index in Elasticsearch?如何在 Elasticsearch 中创建多类型索引?
【发布时间】:2019-05-15 23:43:19
【问题描述】:

在 Elasticsearch 文档的几页中提到了如何查询多类型索引。 但是我一开始就没有创建一个。

这是我的最小示例(在 Elasticsearch 6.x 服务器上):

PUT /myindex
{
  "settings" : {
    "number_of_shards" : 1
  }
}

PUT /myindex/people/123
{
  "first name": "John",
  "last name": "Doe"
}

PUT /myindex/dog/456
{
  "name": "Rex"
}

索引创建和拳头插入做得很好,但是在狗类型插入尝试中:

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Rejecting mapping update to [myindex] as the final mapping would have more than 1 type: [people, dog]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Rejecting mapping update to [myindex] as the final mapping would have more than 1 type: [people, dog]"
  },
  "status": 400
}

但这正是我想要做的,伙计!我的索引中有“超过 1 种类型”。

您知道我必须在调用中进行哪些更改才能实现这一目标吗?

非常感谢。

【问题讨论】:

标签: elasticsearch elasticsearch-6


【解决方案1】:

从 Elastic 6.0.0 开始不支持多种映射类型。详情请见breaking changes

您仍然可以通过实现自己的自定义类型字段来有效地使用多种类型。

例如:

{
    "mappings": {
        "doc": {
            "properties": {
                "type": {
                    "type": "keyword"
                },
                "first_name": {
                    "type": "text"
                },
                "last_name": {
                    "type": "text"
                }

            }
        }
    }
}

这在removal of types中有描述。

【讨论】:

    猜你喜欢
    • 2013-12-28
    • 2017-06-03
    • 2014-03-15
    • 2018-09-01
    • 2016-08-20
    • 2019-06-19
    • 1970-01-01
    • 1970-01-01
    • 2022-10-07
    相关资源
    最近更新 更多