elasticsearch - 在哪里放置 include_type_name 在 config.exs
问题描述
我想从我的 elixir config.exs 文件创建一个 Elasticsearch 7.x 索引:
config :app_core, App.Tools.ElasticsearchCluster,
url: System.get_env("ELASTIC_HOST"),
# username: "username",
# password: "password",
api: Elasticsearch.API.HTTP,
json_library: Poison,
indexes: %{
indie: %{
settings: "priv/elasticsearch/indies.json",
store: App.Tools.ElasticSearch.Indie.Store,
sources: [App.Data.Schema.Indie],
bulk_page_size: 5000,
bulk_wait_interval: 15_000
}
}
priv/elasticsearch/indies.json
开始于
{
"mappings": {
"_doc": {
"properties": {
"category" : {
"type": "nested",
"properties" : {
但是,当我尝试创建索引时,出现错误
"The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true."
有谁知道如何在我引用的上下文中解决这个问题(把它放在特定查询前面是行不通的)?
应 Assael Azran 的要求,这里是完整的 indies.json:
{
"mappings": {
"_doc": {
"properties": {
"category" : {
"type": "nested",
"properties" : {
"all_parents" : {
"type" : "keyword"
},
"direct_parent" : {
"type" : "keyword"
},
"paths" : {
"type" : "keyword"
}
}
},
"slug": {
"type": "keyword"
},
"parent_id": {
"type": "integer",
"index": false
},
"images": {
"type": "nested",
"properties": {
"indie_url": {
"type": "text",
"index": false
}
}
},
"tenant": {
"type": "keyword"
},
"suggest_keywords": {
"type": "completion",
"contexts": [
{
"name": "tenant",
"type": "category"
}
]
},
"name": {
"type": "text"
},
"description": {
"type": "text",
"index": false
},
"updated_at": {
"type": "date"
},
"string_facet": {
"type": "nested",
"properties": {
"id": {
"type": "keyword"
},
"value": {
"type": "keyword"
}
}
},
"number_facet": {
"type": "nested",
"properties": {
"id": {
"type": "keyword"
},
"value": {
"type": "double"
}
}
}
}
}
}
}
解决方案
7.x 版不再支持映射类型。
Elasticsearch 7.x 不推荐在请求中指定类型。例如,索引文档不再需要文档类型。新的索引 API 是 PUT {index}/_doc/{id} 用于显式 ID 和 POST {index}/_doc 用于自动生成的 ID。请注意,在 7.0 中,_doc 是路径的永久部分,表示端点名称而不是文档类型。索引创建、索引模板和映射 API 中的 include_type_name 参数将默认为 false。完全设置参数将导致弃用警告。默认映射类型已删除。
我的建议是_doc
从您的映射中删除类型。
{“映射”:{“属性”:{“类别”:{“类型”:“嵌套”,“属性”:{
更新
在弹性 7.2.0 上测试
我尝试创建以下映射:
PUT my_index
{
"mappings": {
"_doc": {
"properties": {
"category": {
"type": "nested",
"properties": {
"all_parents": {
"type": "keyword"
},
"direct_parent": {
"type": "keyword"
},
"paths": {
"type": "keyword"
}
}
},
"slug": {
"type": "keyword"
},
"parent_id": {
"type": "integer",
"index": false
},
"images": {
"type": "nested",
"properties": {
"indie_url": {
"type": "text",
"index": false
}
}
},
"tenant": {
"type": "keyword"
},
"suggest_keywords": {
"type": "completion",
"contexts": [
{
"name": "tenant",
"type": "category"
}
]
},
"name": {
"type": "text"
},
"description": {
"type": "text",
"index": false
},
"updated_at": {
"type": "date"
},
"string_facet": {
"type": "nested",
"properties": {
"id": {
"type": "keyword"
},
"value": {
"type": "keyword"
}
}
},
"number_facet": {
"type": "nested",
"properties": {
"id": {
"type": "keyword"
},
"value": {
"type": "double"
}
}
}
}
}
}
}
正如预期的那样,我得到了这个错误:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true."
}
],
"type": "illegal_argument_exception",
"reason": "The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true."
},
"status": 400
}
当我_doc
从映射中删除时:
PUT my_index
{
"mappings": {
"properties": {
"category": {
"type": "nested",
"properties": {
"all_parents": {
"type": "keyword"
},
"direct_parent": {
"type": "keyword"
},
"paths": {
"type": "keyword"
}
}
},
"slug": {
"type": "keyword"
},
"parent_id": {
"type": "integer",
"index": false
},
"images": {
"type": "nested",
"properties": {
"indie_url": {
"type": "text",
"index": false
}
}
},
"tenant": {
"type": "keyword"
},
"suggest_keywords": {
"type": "completion",
"contexts": [
{
"name": "tenant",
"type": "category"
}
]
},
"name": {
"type": "text"
},
"description": {
"type": "text",
"index": false
},
"updated_at": {
"type": "date"
},
"string_facet": {
"type": "nested",
"properties": {
"id": {
"type": "keyword"
},
"value": {
"type": "keyword"
}
}
},
"number_facet": {
"type": "nested",
"properties": {
"id": {
"type": "keyword"
},
"value": {
"type": "double"
}
}
}
}
}
}
我明白了
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "my_index"
}
推荐阅读
- javascript - 如何编写一个可以接受一个或多个参数并返回加法的函数
- java - 错误 - 在 Jparepository 中不起作用的日期之间
- android - Android 蓝牙信标唯一标识符
- python - animation.FuncAnimation 贴图
- amazon-web-services - 为 API Gateway lambda 授权者设置 CORS 标头时出错
- r - 获取 R data.table 中一行中最后一个非 NA 值的位置
- intellij-idea - 如何在纯 java 中设置 flink 并行度(IDEA)
- c++ - 如何使用 C++ 在命令行中创建一个简单的字符控制器?
- php - 基于 Laravel 查询 id 的数组
- c - 通过 FreeRTOS 中的队列发送指向结构的指针