87

Hi all I am trying to create schema Test.

PUT /test
{
    "mappings": {
        "field1": {
            "type": "integer"
        },
        "field2": {  
            "type": "integer"
        },
        "field3": {
            "type": "string",
            "index": "not_analyzed"
        },
        "field4": {
            "type": "string",
            "analyzer": "autocomplete",
            "search_analyzer": "standard"
        }
    },
    "settings": {
        bla
        bla
        bla
    }
}

I am getting the following error

{
    "error": {
        "root_cause": [{
            "type": "mapper_parsing_exception",
            "reason": "Root mapping definition has unsupported parameters: [index : not_analyzed] [type : string]"
        }],
        "type": "mapper_parsing_exception",
        "reason": "Failed to parse mapping [featured]: Root mapping definition has unsupported parameters:  [index : not_analyzed] [type : string]",
        "caused_by": {
            "type": "mapper_parsing_exception",
            "reason": "Root mapping definition has unsupported parameters:  [index : not_analyzed] [type : string]"
        }
    },
    "status": 400
}

Please help me to resolve this error

shriek
  • 4,720
  • 7
  • 38
  • 66
Ramesh
  • 1,622
  • 1
  • 17
  • 28

6 Answers6

129

You're almost here, you're just missing a few things:

PUT /test
{
  "mappings": {
    "type_name": {                <--- add the type name
      "properties": {             <--- enclose all field definitions in "properties"
        "field1": {
          "type": "integer"
        },
        "field2": {
          "type": "integer"
        },
        "field3": {
          "type": "string",
          "index": "not_analyzed"
        },
        "field4,": {
          "type": "string",
          "analyzer": "autocomplete",
          "search_analyzer": "standard"
        }
      }
    }
  },
  "settings": {
     ...
  }
}

UPDATE

If your index already exists, you can also modify your mappings like this:

PUT test/_mapping/type_name
{
    "properties": {             <--- enclose all field definitions in "properties"
        "field1": {
          "type": "integer"
        },
        "field2": {
          "type": "integer"
        },
        "field3": {
          "type": "string",
          "index": "not_analyzed"
        },
        "field4,": {
          "type": "string",
          "analyzer": "autocomplete",
          "search_analyzer": "standard"
        }
    }
}

UPDATE:

As of ES 7, mapping types have been removed. You can read more details here

Val
  • 165,097
  • 10
  • 260
  • 279
  • Thanks . Is it possible to create a mapping without typename . I want to insert data without typename Something like {field1,field2 ....} And not like typeName{field1,field2 ...} – Ramesh Sep 06 '16 at 06:29
  • 1
    Okay here What is test and what is type_name? – Ramesh Sep 06 '16 at 06:40
  • 6
    `test` is your index name and `type_name` is the name of your mapping type. – Val Sep 06 '16 at 06:43
  • what is the syntax for 5.6 if you have parent-child, the docs have example but it fails for me – Kalpesh Soni Jan 17 '19 at 19:32
  • @KalpeshSoni feel free to ask another question with specific details to your case – Val Jan 17 '19 at 19:45
  • 2
    copy pasted this code. it gives error: "type": "mapper_parsing_exception", "reason": "Root mapping definition has unsupported parameters: [type_name : {properties={field1={type=integer}, field4,={search_analyzer=standard, analyzer=autocomplete, type=string}, field3={index=not_analyzed, type=string}, field2={type=integer}}}]" – Ramesh Pareek Apr 14 '19 at 03:39
  • All I was missing was the ` "type_name": {`. Thanks! – Tadej Jun 17 '19 at 07:50
  • 1
    For me, the `type_name` is not working. I'm using the elasticsearch-oss:7.20 docker image – Sebastialonso Jul 11 '19 at 21:04
23

I hope the above answer works for elastic search <7.0 but in 7.0 we cannot specify doc type and it is no longer supported. And in that case if we specify doc type we get similar error.

I you are making use of Elastic search 7.0 and Nest C# lastest version(6.6). There are some breaking changes with ES 7.0 which is causing this issue. This is because we cannot specify doc type and in the version 6.6 of NEST they are using doctype. So in order to solve that untill NEST 7.0 is released, we need to download their beta package

Please go through this link for fixing it

https://xyzcoder.github.io/elasticsearch/nest/2019/04/12/es-70-and-nest-mapping-error.html

EDIT: NEST 7.0 is now released. NEST 7.0 works with Elastic 7.0. See the release notes here for details.

dybzon
  • 761
  • 2
  • 11
  • 17
7

Check your Elastic version.

I had these problem because I was looking at the incorrect version's documentation.

enter image description here

slm
  • 12,534
  • 12
  • 87
  • 106
qarly_blue
  • 185
  • 2
  • 5
6

As of ES 7, mapping types have been removed. You can read more details here

If you are using Ruby On Rails this means that you may need to remove document_type from your model or concern.

As an alternative to mapping types one solution is to use an index per document type.

Before:

module Searchable
  extend ActiveSupport::Concern

  included do
    include Elasticsearch::Model
    include Elasticsearch::Model::Callbacks
    index_name [Rails.env, Rails.application.class.module_parent_name.underscore].join('_')
    document_type self.name.downcase
  end
end

After:

module Searchable
  extend ActiveSupport::Concern

  included do
    include Elasticsearch::Model
    include Elasticsearch::Model::Callbacks
    index_name [Rails.env, Rails.application.class.module_parent_name.underscore, self.name.downcase].join('_')
  end
end
null
  • 3,195
  • 1
  • 17
  • 27
1

I am running Elastic Search version 7.12

When I run the following command

curl -H 'Content-Type: application/json' -XPUT 127.0.0.1:9200/movies?pretty -d '
{
    "mappings" : {
        "movie": {
            "properties" : {
                "year" : { "type": "date" }
            }
        }
    }   
}'

the following error is returned.

{
  "error" : {
    "root_cause" : [
      {
        "type" : "mapper_parsing_exception",
        "reason" : "Root mapping definition has unsupported parameters:  [movie : {properties={year={type=date}}}]"
      }
    ],
    "type" : "mapper_parsing_exception",
    "reason" : "Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters:  [movie : {properties={year={type=date}}}]",
    "caused_by" : {
      "type" : "mapper_parsing_exception",
      "reason" : "Root mapping definition has unsupported parameters:  [movie : {properties={year={type=date}}}]"
    }
  },
  "status" : 400
}

To mitigate that, modify the json in the query as follows.

curl -H 'Content-Type: application/json' -XPUT 127.0.0.1:9200/movies?pretty -d '
{
    "mappings" : {
        "properties" : {
            "year" : { "type": "date" }
        }
    }   
}'

Note: Removed the "movie":{} layer. Now it works.

VivekDev
  • 7,143
  • 11
  • 58
  • 107
0
PUT /testIndex
{
    "mappings": {
        "properties": {     <--ADD THIS
            "field1": {
                "type": "integer"
            },
            "field2": {  
                "type": "integer"
            },
            "field3": {
                "type": "string",
                "index": "not_analyzed"
            },
            "field4": {
                "type": "string",
                "analyzer": "autocomplete",
                "search_analyzer": "standard"
            }
        }
    },
    "settings": {
        bla
        bla
        bla
    }
}

Here's a similar command I know works:

curl -v -H "Content-Type: application/json" -H "Authorization: Basic cGC3COJ1c2Vy925hZGFJbXBvcnABCnRl" -X PUT -d '{"mappings":{"properties":{"city":{"type": "text"}}}}' https://35.80.2.21/manzanaIndex

The breakdown for the above curl command is:

PUT /manzanaIndex
{
    "mappings":{
        "properties":{
                "city":{
                    "type": "text"
                }
        }
    }
}
Gene
  • 9,441
  • 1
  • 60
  • 54