Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch mapping not working

Trying to create mapping under Elasticsearch 2 with the following command, but it fails:

POST /my_blog    
{
    "settings": {
        "index" : {
            "number_of_shards" : 10
        }
    },     
    "mappings": {
        "post" : {        
            "_routing" : {
                "required": false,
                "path" : "post_date"
            },
            "properties": {
                "user_id" :{
                    "type": "integer"                    
                },
                "post_text" : {
                    "type": "string"                    
                },
                "post_date": {
                    "type" : "date",
                    "format" : "YYYY-MM-DD"
                }
            }
        }
    }
}

Response:

{
   "error": {
      "root_cause": [
         {
            "type": "mapper_parsing_exception",
            "reason": "Mapping definition for [_routing] has unsupported parameters:  [path : post_date]"
         }
      ],
      "type": "mapper_parsing_exception",
      "reason": "mapping [post]",
      "caused_by": {
         "type": "mapper_parsing_exception",
         "reason": "Mapping definition for [_routing] has unsupported parameters:  [path : post_date]"
      }
   },
   "status": 400
}

It doesn't matter what field I choose for the path, integer/string or date, it always gives the same error reply (see above). Any ideas?

like image 212
Adam Szabo Avatar asked Nov 19 '15 17:11

Adam Szabo


1 Answers

Take a look at the type meta-field changes in 2.0. What you're trying to do can't be done anymore.

You'll have to create the index like this:

POST /my_blog    
{
    "settings": {
        "index" : {
            "number_of_shards" : 10
        }
    },     
    "mappings": {
        "post" : {        
            "_routing" : {
                "required": false
            },
            "properties": {
                "user_id" :{
                    "type": "integer"                    
                },
                "post_text" : {
                    "type": "string"                    
                },
                "post_date": {
                    "type" : "date",
                    "format" : "YYYY-MM-DD"
                }
            }
        }
    }
}

Then specify the routing in the query string of each indexed document, like:

PUT /my_blog/post/1?routing=2015-11-19
{
    "user_id": 1,
    "post_text": "Lorem ipsum",
    "post_date": "2015-11-19"
}
like image 129
Sloan Ahrens Avatar answered Nov 03 '22 23:11

Sloan Ahrens