# Add mapping for geo\_point with java

**URL:** <https://discuss.elastic.co/t/add-mapping-for-geo-point-with-java/23526>\
**Category:** Elasticsearch\
**Created:** [May 4, 2015, 6:32am UTC](https://discuss.elastic.co/t/add-mapping-for-geo-point-with-java/23526 "2015-05-04T06:32:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dharshana\_Ratnayake](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@Dharshana\_Ratnayake](https://discuss.elastic.co/u/Dharshana_Ratnayake)\
**Post date:** [May 4, 2015, 6:32am UTC](https://discuss.elastic.co/t/add-mapping-for-geo-point-with-java/23526/1 "2015-05-04T06:32:51Z")

</div>

Hi Guys

Im trying to save documents in elasticsearch where one field i want to map  
a geo\_point with lat and lon  
But i would like to do this through java because i create my index through  
java code

i tried

```
        XContentBuilder builder = XContentFactory.jsonBuilder().

```

startObject().startObject("unitStatus").startObject("properties");

```
        builder.startObject("location")

            .field("type", "geo_point")

            .field("store", "yes")

            .endObject();

```

but that does not seem to work. When i query th empaling i get

curl -XGET  
'[http://127.0.0.1:9200/test\_lost\_victories1\_unit\_status/\_mapping?pretty=1](http://127.0.0.1:9200/test_lost_victories1_unit_status/_mapping?pretty=1)'

{

"test\_lost\_victories1\_unit\_status" : {

```
"mappings" : {

  "unitStatus" : {

    "properties" : {   

      

      "location" : {

        "properties" : {

          "lat" : {

            "type" : "double"

          },

          "lon" : {

            "type" : "double"

          }

        }

      }

     

   }

  }

}

```

}

}

And when i query by location i get a  
QueryParsingException[[test\_lost\_victories1\_unit\_status] failed to find  
geo\_point field [location]];

Any help with how to correctly map a geo point using the java api would be  
greatly appreciated  
thanks  
Dharshana

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1b10e111-5d82-481a-8b85-5b7e7c86f631%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1b10e111-5d82-481a-8b85-5b7e7c86f631%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 4, 2015, 6:40am UTC](https://discuss.elastic.co/t/add-mapping-for-geo-point-with-java/23526/2 "2015-05-04T06:40:53Z")

</div>

How do you send your mapping?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

> Le 4 mai 2015 à 08:32, Dharshana Ratnayake [darthshana@gmail.com](mailto:darthshana@gmail.com) a écrit :
> 
> Hi Guys
> 
> Im trying to save documents in elasticsearch where one field i want to map a geo\_point with lat and lon  
> But i would like to do this through java because i create my index through java code
> 
> i tried  
> XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("unitStatus").startObject("properties");
> 
> ```
> builder.startObject("location")
> 
> .field("type", "geo_point")
> 
> .field("store", "yes")
> 
> .endObject();
> 
> ```
> 
> but that does not seem to work. When i query th empaling i get  
> curl -XGET '[http://127.0.0.1:9200/test\_lost\_victories1\_unit\_status/\_mapping?pretty=1](http://127.0.0.1:9200/test_lost_victories1_unit_status/_mapping?pretty=1)'
> 
> {
> 
> "test\_lost\_victories1\_unit\_status" : {
> 
> ```
> "mappings" : {
> 
> "unitStatus" : {
> 
> "properties" : {  
>      
> "location" : {
> 
> "properties" : {
> 
> "lat" : {
> 
> "type" : "double"
> 
> },
> 
> "lon" : {
> 
> "type" : "double"
> 
> }
> 
> }
> 
> }
>      
> }
> 
> }
> 
> }
> 
> ```
> 
> }
> 
> }
> 
> And when i query by location i get a  
> QueryParsingException[[test\_lost\_victories1\_unit\_status] failed to find geo\_point field [location]];
> 
> ## Any help with how to correctly map a geo point using the java api would be greatly appreciated thanks Dharshana
> 
> 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).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1b10e111-5d82-481a-8b85-5b7e7c86f631%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1b10e111-5d82-481a-8b85-5b7e7c86f631%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/8C72A261-1D03-4230-B84C-248CA33A37F4%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/8C72A261-1D03-4230-B84C-248CA33A37F4%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Dharshana\_Ratnayake](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@Dharshana\_Ratnayake](https://discuss.elastic.co/u/Dharshana_Ratnayake)\
**Post date:** [May 4, 2015, 6:57am UTC](https://discuss.elastic.co/t/add-mapping-for-geo-point-with-java/23526/3 "2015-05-04T06:57:21Z")

</div>

I don't think I am.. ☹

guess I'm missing

createIndexRequestBuilder.addMapping(documentType, mappingBuilder);  
// MAPPING DONE  
createIndexRequestBuilder.execute().actionGet();

i just ran

CreateIndexRequest request = new CreateIndexRequest(indexName);

```
       CreateIndexResponse response = adminClient.create(request).

```

actionGet();

```
       if (!response.isAcknowledged()) {

           throw new RuntimeException("Failed to delete index " + 

```

indexName);

```
       }

       System.out.println("created index:"+indexName);          

        XContentBuilder builder = XContentFactory.jsonBuilder().

```

startObject().startObject("unitStatus").startObject("properties");

```
       builder.startObject("location")

           .field("type", "geo_point")

           .field("store", "yes")

           .endObject();

```

though that would be enough.. thanks for you help!!!

On Monday, 4 May 2015 18:41:12 UTC+12, David Pilato wrote:

> How do you send your mapping?
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 4 mai 2015 à 08:32, Dharshana Ratnayake \<[darth...@gmail.com](mailto:darth...@gmail.com)  
> \<javascript:\>\> a écrit :
> 
> Hi Guys
> 
> Im trying to save documents in elasticsearch where one field i want to map  
> a geo\_point with lat and lon  
> But i would like to do this through java because i create my index through  
> java code
> 
> i tried
> 
> ```
> XContentBuilder builder = XContentFactory.jsonBuilder().
> 
> ```
> 
> startObject().startObject("unitStatus").startObject("properties");
> 
> ```
> builder.startObject("location")
> 
> .field("type", "geo_point")
> 
> .field("store", "yes")
> 
> .endObject();
> 
> ```
> 
> but that does not seem to work. When i query th empaling i get
> 
> curl -XGET '  
> [http://127.0.0.1:9200/test\_lost\_victories1\_unit\_status/\_mapping?pretty=1](http://127.0.0.1:9200/test_lost_victories1_unit_status/_mapping?pretty=1)'
> 
> {
> 
> "test\_lost\_victories1\_unit\_status" : {
> 
> ```
> "mappings" : {
> 
> "unitStatus" : {
> 
> "properties" : {   
> 
>       
> 
> "location" : {
> 
> "properties" : {
> 
> "lat" : {
> 
> "type" : "double"
> 
> },
> 
> "lon" : {
> 
> "type" : "double"
> 
> }
> 
> }
> 
> }
> 
>      
> 
> }
> 
> }
> 
> }
> 
> ```
> 
> }
> 
> }
> 
> And when i query by location i get a  
> QueryParsingException[[test\_lost\_victories1\_unit\_status] failed to find  
> geo\_point field [location]];
> 
> Any help with how to correctly map a geo point using the java api would be  
> greatly appreciated  
> thanks  
> Dharshana
> 
> --  
> 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/1b10e111-5d82-481a-8b85-5b7e7c86f631%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1b10e111-5d82-481a-8b85-5b7e7c86f631%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/1b10e111-5d82-481a-8b85-5b7e7c86f631%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/1b10e111-5d82-481a-8b85-5b7e7c86f631%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/47358eff-1f02-4ded-8313-9552cdbe831e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/47358eff-1f02-4ded-8313-9552cdbe831e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:16am UTC](https://discuss.elastic.co/t/add-mapping-for-geo-point-with-java/23526/4 "2017-07-06T00:16:02Z")

</div>


