Elasticsearch : Root mapping definition has unsupp

2019-02-11 17:43发布

问题:

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

回答1:

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