Pau*_*eau 10 elixir elasticsearch
我想从我的 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
}
}
Run Code Online (Sandbox Code Playgroud)
该priv/elasticsearch/indies.json开头
{
"mappings": {
"_doc": {
"properties": {
"category" : {
"type": "nested",
"properties" : {
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试创建索引时,出现错误
"The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true."
Run Code Online (Sandbox Code Playgroud)
有谁知道如何在我引用的上下文中解决这个问题(将它放在特定查询的前面是行不通的)?
应 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"
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
Ass*_*ran 21
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"
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
正如预期的那样,我收到此错误:
{
"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
}
Run Code Online (Sandbox Code Playgroud)
当我_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"
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我明白了
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "my_index"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7654 次 |
| 最近记录: |