简体   繁体   中英

Mapping format on elasticsearch

I'm to upload a json document to my server via elasticsearch but i wanted to map it before i upload it but i keep getting a search phase execution exception error. The json data looks like this

{"geometry":{"type":"Point","coordinates":[-73.20266100000001,45.573647]},"properties":{"persistent_id":"XVCPFsbsqB7h4PrxEtCU3w==","timestamp":1408216040000,"tower_id":"10.48.66.178"}}

So far i've tried this as my mapping. Im not sure what i am doing wrong...

curl –XPUT 'http://localhost:9200/carrier/_search?q=coordinates?pretty=true' -d'
{ “geometry”: {
“type” : {“type” : “string”},
“coordinates” : {“type”  : “geo_point”}
},
“properties” : { 
“persistent_id” : {“type” : “string”},
“timestamp”: { “type” : “long”},
“tower_id” : {“type” : “string”}
}'

This is because you're using the _search endpoint in order to install your mapping.

You have to use the _mapping endpoint instead, like this:

curl –XPUT 'http://localhost:9200/carrier/_mapping/geometry' -d '{
    ...your mapping...
}'

There are a few problems here. First of all you need to use put mapping request instead of search request. The body of the request has to start with the name of the type followed by the list of properties (fields) that you add. The second problem is that you probably copied the example from some documentation where all ascii quotes ( " ) were replaced with replaced with their fancy unicode versions ( and ) and dash in front of the XPUT parameter looks like n-dash instead of normal dash - . You need to replace all fancy quotes and dashes with their ascii versions. So, all together the working statement should look like this (assuming doc as your document type):

curl -XPUT 'http://localhost:9200/carrier/doc/_mapping' -d '{
    "doc": {
        "properties": {
            "geometry": {
                "properties": {
                    "type": {
                        "type": "string"
                    },
                    "coordinates": {
                        "type": "geo_point"
                    }
                }
            },
            "properties": {
                "properties": {
                    "persistent_id": {
                        "type": "string"
                    },
                    "timestamp": {
                        "type": "long"
                    },
                    "tower_id": {
                        "type": "string"
                    }
                }
            }

        }
    }
}'

then you can add document like this:

curl -XPUT 'http://localhost:9200/carrier/doc/1' -d '{"geometry":{"type":"Point","coordinates":[-73.20266100000001,45.573647]},"properties":{"persistent_id":"XVCPFsbsqB7h4PrxEtCU3w==","timestamp":1408216040000,"tower_id":"10.48.66.178"}}'

Please note that in order to add the mapping you might need to delete and recreate the index if you already tried to add documents to this index and the mapping was already created.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM