Add mapping for geo_point with java

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'

{

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

How do you send your mapping?

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

Le 4 mai 2015 à 08:32, Dharshana Ratnayake 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'

{

"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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/1b10e111-5d82-481a-8b85-5b7e7c86f631%40googlegroups.com.
For more options, visit 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/8C72A261-1D03-4230-B84C-248CA33A37F4%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.

I don't think I am.. :frowning:

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 :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 4 mai 2015 à 08:32, Dharshana Ratnayake <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'

{

"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 <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?utm_medium=email&utm_source=footer
.
For more options, visit 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/47358eff-1f02-4ded-8313-9552cdbe831e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.