# Pig to Elasticsearch - Geospatial

**URL:** <https://discuss.elastic.co/t/pig-to-elasticsearch-geospatial/13978>\
**Category:** Elasticsearch\
**Created:** [October 16, 2013, 8:40pm UTC](https://discuss.elastic.co/t/pig-to-elasticsearch-geospatial/13978 "2013-10-16T20:40:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![david\_fauth](https://avatars.discourse-cdn.com/v4/letter/d/e495f1/32.png) [@david\_fauth](https://discuss.elastic.co/u/david_fauth)\
**Post date:** [October 16, 2013, 8:40pm UTC](https://discuss.elastic.co/t/pig-to-elasticsearch-geospatial/13978/1 "2013-10-16T20:40:01Z")

</div>

Set up a mapping as follows:

curl -XPUT [http://localhost:9200/us\_large\_cities](http://localhost:9200/us_large_cities) -d '  
{  
"mappings": {  
"city": {  
"properties": {  
"city": {"type": "string"},  
"state": {"type": "string"},  
"location": {"type": "geo\_point"}  
}  
}  
}  
}  
'

Tried the following Pig job to write to elasticsearch.

register '/Users/davidfauth/Downloads/elasticsearch-hadoop-1.3.0.M1.jar';  
define ESStorage  
org.elasticsearch.hadoop.pig.ESStorage('es.resource=us\_large\_cities/city');

city\_data = LOAD '/Users/davidfauth/jsonTest/locations.csv' USING  
PigStorage('\t') AS  
(city:chararray,  
state:chararray,  
lat:chararray,  
lon:chararray);

-- ETL the data to your heart content  
B = FOREACH city\_data GENERATE city, state, TOTUPLE(lat, lon) AS location;  
-- save the result to Elasticsearch  
STORE B INTO 'us\_large\_cities/city' USING  
org.elasticsearch.hadoop.pig.ESStorage();

Error returned is:

JAVA UDF ERROR: java.lang.StringIndexOutOfBoundsException: String index out  
of range: -1  
at java.lang.String.substring(String.java:1911)  
at org.elasticsearch.hadoop.rest.Resource.(Resource.java:43)

thoughts/ideas?

thanks  
df

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 2:12am UTC](https://discuss.elastic.co/t/pig-to-elasticsearch-geospatial/13978/2 "2017-07-06T02:12:05Z")

</div>


