Elasticsearch geo_point mapping issue


(Muhammad Ali Tahir) #1

I'm working on node js (version 6.1.0 ) application and using elasticsearch (version 5.0.1) in it. But I'm having issues in geo_point query.

The schema of my elasticsearch after assigning mapping is as follows,

{
"newtesting": {
	"aliases": {},
	"mappings": {
		"newtesting": {
			"properties": {
				"location": {
					"properties": {
						"pin": {
							"properties": {
								"location": {
									"type": "geo_shape"
								}
							}
						}
					}
				}
			}
		}
	},

and when I insert values through this code,

    PUT /newtesting/newtesting/1
{
"pin" : {
    "location" : {
        "lat" : 40.12,
        "lon" : -71.34
    }
}

}

then my mapping gets changed like this,

{
"newtesting": {
	"aliases": {},
	"mappings": {
		"newtesting": {
			"properties": {
				"location": {
					"properties": {
						"pin": {
							"properties": {
								"location": {
									"type": "geo_shape"
								}
							}
						}
					}
				},
				"pin": {
					"properties": {
						"location": {
							"properties": {
								"lat": {
									"type": "float"
								},
								"lon": {
									"type": "float"
								}
							}
						}
					}
				}
			}
		}
	},

Due to which my geo_point search query gives this error

"[query_shard_exception] failed to find geo_point field [pin.location]"

Anyone who has some idea about this?


(David Pilato) #2

Please don't post images of text as they are hardly readable and not searchable.

Instead paste the text and format it with </> icon. Check the preview window.

Please update your question.


(Muhammad Ali Tahir) #3

Sorry for that, is it okay now?


(David Pilato) #4

Some comments.

The mapping you created indicates that you are writing (I think) in an index called newtesting and the document type is newtesting.

But then you index with PUT /my_locations/location/1 where index name is my_locations and type is location.

Are you sure your example is correct?

Could you provide a full recreation script as described in

It will help to better understand what you are doing.
Please, try to keep the example as simple as possible.


(Muhammad Ali Tahir) #5

sorry there was a typing mistake, see my example again


(David Pilato) #6

According to your mapping you should write:

PUT /newtesting/newtesting/1
{
"location" : {
  "pin" : {
    "location" : {
        "lat" : 40.12,
        "lon" : -71.34
    }
  }
}

(Muhammad Ali Tahir) #7

It worked. Thank you so much for the help


(system) #8

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.