I want to create an Elasticsearch 7.x index from my elixir config.exs file:
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 } } The priv/elasticsearch/indies.json begins with
{ "mappings": { "_doc": { "properties": { "category" : { "type": "nested", "properties" : { However, when I try to create the index, I get error
"The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true." Does anyone know how to solve this problem in the context I referenced (Putting it in front of a specific query won't work)?
Upon request from Assael Azran, here is the full 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" } } } } } } } 1 Answer
Mapping types are no longer supported in versions 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.
My suggestion is to remove _doc type from your mappings.
{ "mappings": { "properties": { "category" : { "type": "nested", "properties" : {
UPDATE
Tested on elastic 7.2.0
I've tried to create the following mappings:
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" } } } } } } } And as expected i get this error:
{ "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 } When i remove _doc from mappings:
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" } } } } } } I get this
{ "acknowledged" : true, "shards_acknowledged" : true, "index" : "my_index" } 7