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

**URL:** <https://discuss.elastic.co/t/how-to-store-a-geo-point-csv-file-contents-in-elasticsearch-and-use-it-in-a-query-filter-against-a-field-in-an-index/131111>\
**Category:** Elasticsearch\
**Created:** [May 9, 2018, 6:53am UTC](https://discuss.elastic.co/t/how-to-store-a-geo-point-csv-file-contents-in-elasticsearch-and-use-it-in-a-query-filter-against-a-field-in-an-index/131111 "2018-05-09T06:53:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![frehman\_pk](https://avatars.discourse-cdn.com/v4/letter/f/7ab992/32.png) [@frehman\_pk](https://discuss.elastic.co/u/frehman_pk)\
**Post date:** [May 9, 2018, 6:53am UTC](https://discuss.elastic.co/t/how-to-store-a-geo-point-csv-file-contents-in-elasticsearch-and-use-it-in-a-query-filter-against-a-field-in-an-index/131111/1 "2018-05-09T06:53:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 9, 2018, 6:56am UTC](https://discuss.elastic.co/t/how-to-store-a-geo-point-csv-file-contents-in-elasticsearch-and-use-it-in-a-query-filter-against-a-field-in-an-index/131111/2 "2018-05-09T06:56:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![frehman\_pk](https://avatars.discourse-cdn.com/v4/letter/f/7ab992/32.png) [@frehman\_pk](https://discuss.elastic.co/u/frehman_pk)\
**Post date:** [May 9, 2018, 7:02am UTC](https://discuss.elastic.co/t/how-to-store-a-geo-point-csv-file-contents-in-elasticsearch-and-use-it-in-a-query-filter-against-a-field-in-an-index/131111/3 "2018-05-09T07:02:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 9, 2018, 7:16am UTC](https://discuss.elastic.co/t/how-to-store-a-geo-point-csv-file-contents-in-elasticsearch-and-use-it-in-a-query-filter-against-a-field-in-an-index/131111/4 "2018-05-09T07:16:44Z")

</div>

> [@frehman\_pk](#):
>
> where i should store the file content to query based on field

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

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 9, 2018, 7:28am UTC](https://discuss.elastic.co/t/how-to-store-a-geo-point-csv-file-contents-in-elasticsearch-and-use-it-in-a-query-filter-against-a-field-in-an-index/131111/5 "2018-05-09T07:28:40Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![frehman\_pk](https://avatars.discourse-cdn.com/v4/letter/f/7ab992/32.png) [@frehman\_pk](https://discuss.elastic.co/u/frehman_pk)\
**Post date:** [May 9, 2018, 7:33am UTC](https://discuss.elastic.co/t/how-to-store-a-geo-point-csv-file-contents-in-elasticsearch-and-use-it-in-a-query-filter-against-a-field-in-an-index/131111/6 "2018-05-09T07:33:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 9, 2018, 7:34am UTC](https://discuss.elastic.co/t/how-to-store-a-geo-point-csv-file-contents-in-elasticsearch-and-use-it-in-a-query-filter-against-a-field-in-an-index/131111/7 "2018-05-09T07:34:33Z")

</div>

Please show a sample document.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 9, 2018, 7:37am UTC](https://discuss.elastic.co/t/how-to-store-a-geo-point-csv-file-contents-in-elasticsearch-and-use-it-in-a-query-filter-against-a-field-in-an-index/131111/8 "2018-05-09T07:37:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![frehman\_pk](https://avatars.discourse-cdn.com/v4/letter/f/7ab992/32.png) [@frehman\_pk](https://discuss.elastic.co/u/frehman_pk)\
**Post date:** [May 9, 2018, 7:39am UTC](https://discuss.elastic.co/t/how-to-store-a-geo-point-csv-file-contents-in-elasticsearch-and-use-it-in-a-query-filter-against-a-field-in-an-index/131111/9 "2018-05-09T07:39:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 6, 2018, 7:39am UTC](https://discuss.elastic.co/t/how-to-store-a-geo-point-csv-file-contents-in-elasticsearch-and-use-it-in-a-query-filter-against-a-field-in-an-index/131111/10 "2018-06-06T07:39:04Z")

</div>

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