include_type_name 放在 config.exs 的什么地方

Where to put include_type_name in 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 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

更新

在 elastic 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"
}