How to store a geo point csv file (contents) in elasticsearch and use it in a query filter against a field in an index


(Faheem) #1

I am new to ES. I have an index of user profiles, index contains geo point data of users along with the other fields. we upload a csv file containing geo points and i need to write a query to filter user based on the geo points provided in the csv file. My question is can i store csv file or its contents in the index or as a separate type in the index to later query based on geo location field in the index.


(Mark Walkom) #2

Yes you can, you just need to make sure you setup a mapping before hand so that the geo data is recognised correctly.


(Faheem) #3

Field mapping is already in place like this.

"properties": {
"location": {
"type": "geo_point"
}
}

where i should store the file content to query based on field. like my query would be fetch all profiles who's location (geo point) exist within 20km of the geo points provided in the csv file.


(Mark Walkom) #4

In Elasticsearch, but I don't think that is what you are asking so can you rephrase your question?


(Christian Dahlqvist) #5

If you have that in your mapping, you need to parse your data and create a location field that looks like this in your documents:

"location": {
  "lon": 12.3456,
  "lat": 23.4567
}

(Faheem) #6

my documents have similar structure as you mentioned. and the query would be something like this

{
"query": {
    "bool" : {
        "must" : {
            "match_all" : {}
        },
        "filter" : {
            "geo_distance" : {
                "distance" : "200km",
                "location" : {
                    "lat" : 40,
                    "lon" : -70
                }
            }
        }
    }
}

}

i want to apply my filter on a file contains lat/lon


(Christian Dahlqvist) #7

Please show a sample document.


(Mark Walkom) #8

You can build it in Kibana with a map visualisation, then copy the query it forms :slight_smile:


(Faheem) #9

sample document looks like

{
"publisher": {
	"custom_pub_red_1": {
		"zip": "",
		"subscribe_date": "2014-07-21",
		"country": "USA",
		"email_user_action_type": 4,
		"gender": "",
		"address2": "",
		"city": "North Hollywood",
		"address1": "",
		"work_phone": "",
		"email_user_id": 2559595717,
		"last_name": "",
		"ip_address": "",
		"email_user_action_date": "2014-07-21",
		"client_id": 2379,
		"source_url": "",
		"domain_id": 7,
		"phone": "",
		"mobile_phone": "",
		"capture_date": "2014-07-21 22:22:03",
		"state": "CA",
		"email_address_md5_upper": "",
		"first_name": "",
		"status": "A",
		"location": {
			"lat": 41.12,
			"lon": -71.34
		}
	}
}

(system) #10

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