gpt4 book ai didi

elasticsearch - 在哪里将include_type_name放在config.exs中

转载 作者:行者123 更新时间:2023-12-02 22:09:39 24 4
gpt4 key购买 nike

我想从我的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 Specifying types in requests is deprecated. For instance, indexing a document no longer requires a document type. The new index APIs are PUT {index}/_doc/{id} in case of explicit ids and POST {index}/_doc for auto-generated ids. Note that in 7.0, _doc is a permanent part of the path, and represents the endpoint name rather than the document type. The include_type_name parameter in the index creation, index template, and mapping APIs will default to false. Setting the parameter at all will result in a deprecation warning. The default mapping type is removed.



我的建议是从映射中删除 _doc类型。

{ "mappings": { "properties": { "category" : { "type": "nested", "properties" : {



From here

更新

在弹性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"
}

关于elasticsearch - 在哪里将include_type_name放在config.exs中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58824489/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com