# ElasticSearch(Java) - searching with the help of location(GeoPoint

**URL:** <https://discuss.elastic.co/t/elasticsearch-java-searching-with-the-help-of-location-geopoint/116866>\
**Category:** Elasticsearch\
**Created:** [January 24, 2018, 12:39pm UTC](https://discuss.elastic.co/t/elasticsearch-java-searching-with-the-help-of-location-geopoint/116866 "2018-01-24T12:39:49Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikita\_Krasnov](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@Nikita\_Krasnov](https://discuss.elastic.co/u/Nikita_Krasnov)\
**Post date:** [January 24, 2018, 12:39pm UTC](https://discuss.elastic.co/t/elasticsearch-java-searching-with-the-help-of-location-geopoint/116866/1 "2018-01-24T12:39:49Z")

</div>

Hello to everyone.  
I try to search by geoShapeQuery:

```
 @PostMapping("/findLogsByValues")
    @Transactional
    public ResponseEntity findLogsByValues(@RequestBody ElasticSearchLogRequest esLogRequest) {
if (esLogRequest.getLocation() != null) {
            try {
                bqb.filter(QueryBuilders.geoShapeQuery("location", ShapeBuilders.
                        newMultiPoint(new CoordinatesBuilder().
                        coordinate(esLogRequest.getLocation().getLat(), esLogRequest.getLocation().getLon()).build())).
                        relation(ShapeRelation.INTERSECTS));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
 sourceBuilder.query(bqb);
searchRequest.source(sourceBuilder);
        SearchResponse searchResponse = null;
        try {
            searchResponse = client.search(searchRequest);
        } catch (IOException e) {
            e.printStackTrace();
        }
}

```

For request I use JSON:  
{  
"location":{  
"lat":50.4501,  
"lon":30.5234  
}  
}

And get such error:  
**_in the comments_**

This is how I saved GeoPoint to ES:

```
try {
            XContentBuilder builder = XContentFactory.jsonBuilder();
            builder.startObject();
            {
                builder.field("location", elasticSearchLogs.getLocation());   
            }
            builder.endObject();
}

```

where getLocation returns GeoPoint (field GeoPoint location)  
When I look through Kibana on saved longitute and latitude I see:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/b/8/b864b03a167af27ed220ace276d56cf94fe32f6a.png)  
What should I do for searching with the help of location(GeoPoint)?

---

<div class="post-metadata">

**Author:** ![Nikita\_Krasnov](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@Nikita\_Krasnov](https://discuss.elastic.co/u/Nikita_Krasnov)\
**Post date:** [January 24, 2018, 12:40pm UTC](https://discuss.elastic.co/t/elasticsearch-java-searching-with-the-help-of-location-geopoint/116866/2 "2018-01-24T12:40:22Z")

</div>

```
2018-01-24 14:30:52.405 ERROR 12932 --- [nio-8082-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is ElasticsearchStatusException[Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]]] with root cause

    org.elasticsearch.ElasticsearchStatusException: Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]
    	at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:177) ~[elasticsearch-6.1.1.jar:6.1.1]
    	at org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:573) ~[elasticsearch-rest-high-level-client-6.1.1.jar:6.1.1]
    	at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:549) ~[elasticsearch-rest-high-level-client-6.1.1.jar:6.1.1]
    	at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:456) ~[elasticsearch-rest-high-level-client-6.1.1.jar:6.1.1]
    	at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:429) ~[elasticsearch-rest-high-level-client-6.1.1.jar:6.1.1]
    	at org.elasticsearch.client.RestHighLevelClient.search(RestHighLevelClient.java:368) ~[elasticsearch-rest-high-level-client-6.1.1.jar:6.1.1]
    	at com.datastech.admin.resource.ElasticSearchResource.findLogsByValues(ElasticSearchResource.java:298) ~[classes/:na]
    	at com.datastech.admin.resource.ElasticSearchResource$$FastClassBySpringCGLIB$$25624506.invoke(<generated>) ~[classes/:na]
    	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    	at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282) ~[spring-tx-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    	at com.datastech.admin.resource.ElasticSearchResource$$EnhancerBySpringCGLIB$$e8644b8a.findLogsByValues(<generated>) ~[classes/:na]
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_152]
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_152]
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_152]
    	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_152]
    	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
```

---

<div class="post-metadata">

**Author:** ![Nikita\_Krasnov](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@Nikita\_Krasnov](https://discuss.elastic.co/u/Nikita_Krasnov)\
**Post date:** [January 24, 2018, 12:41pm UTC](https://discuss.elastic.co/t/elasticsearch-java-searching-with-the-help-of-location-geopoint/116866/3 "2018-01-24T12:41:14Z")

</div>

```
Suppressed: org.elasticsearch.client.ResponseException: method [GET], host [http://192.168.3.43:9200], URI [/_search?typed_keys=true&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&search_type=query_then_fetch&batched_reduce_size=512], status line [HTTP/1.1 400 Bad Request]
{"error":{"root_cause":[{"type":"query_shard_exception","reason":"failed to find geo_shape field [location]","index_uuid":"mXFRna9FRm2_1p9mzT4LeA","index":".kibana"},{"type":"query_shard_exception","reason":"failed to find geo_shape field [location]","index_uuid":"QutuP8lFSFSBh50Xgajv9Q","index":"portal-logs-24.01.2018"},{"type":"query_shard_exception","reason":"failed to find geo_shape field [location]","index_uuid":"x7dXXCrXTnCWBgbgit7O_Q","index":"portal-metrics-19.01.2018"},{"type":"query_shard_exception","reason":"failed to find geo_shape field [location]","index_uuid":"_snEJtiFRf27yco3Gs1Tyw","index":"portal-metrics-22.01.2018"},{"type":"query_shard_exception","reason":"failed to find geo_shape field [location]","index_uuid":"8x-yE_DgRuKkJVykR0ElPA","index":"portal-metrics-23.01.2018"},{"type":"query_shard_exception","reason":"failed to find geo_shape field [location]","index_uuid":"-I_f7jUjRjiHK2h8ye-g6w","index":"portal-user_info-19.01.2018"},{"type":"query_shard_exception","reason":"failed to find geo_shape field [location]","index_uuid":"nY7I_dOTSN-Edofxmk_P3Q","index":"portal-user_info-22.01.2018"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":".kibana","node":"SAPKQLGGSJiR8bMBdkNvfQ","reason":{"type":"query_shard_exception","reason":"failed to find geo_shape field [location]","index_uuid":"mXFRna9FRm2_1p9mzT4LeA","index":".kibana"}},{"shard":0,"index":"portal-logs-24.01.2018","node":"JEwfXRPHQSWjPn4L4U6AVQ","reason":{"type":"query_shard_exception","reason":"failed to find geo_shape field [location]","index_uuid":"QutuP8lFSFSBh50Xgajv9Q","index":"portal-logs-24.01.2018"}},{"shard":0,"index":"portal-metrics-19.01.2018","node":"SAPKQLGGSJiR8bMBdkNvfQ","reason":{"type":"query_shard_exception","reason":"failed to find geo_shape field [location]","index_uuid":"x7dXXCrXTnCWBgbgit7O_Q","index":"portal-metrics-19.01.2018"}},{"shard":0,"index":"portal-metrics-22.01.2018","node":"JEwfXRPHQSWjPn4L4U6AVQ","reason":{"type":"query_shard_exception","reason":"failed to find geo_shape field [location]","index_uuid":"_snEJtiFRf27yco3Gs1Tyw","index":"portal-metrics-22.01.2018"}},{"shard":0,"index":"portal-metrics-23.01.2018","node":"JEwfXRPHQSWjPn4L4U6AVQ","reason":{"type":"query_shard_exception","reason":"failed to find geo_shape field [location]","index_uuid":"8x-yE_DgRuKkJVykR0ElPA","index":"portal-metrics-23.01.2018"}},{"shard":0,"index":"portal-user_info-19.01.2018","node":"JEwfXRPHQSWjPn4L4U6AVQ","reason":{"type":"query_shard_exception","reason":"failed to find geo_shape field [location]","index_uuid":"-I_f7jUjRjiHK2h8ye-g6w","index":"portal-user_info-19.01.2018"}},{"shard":0,"index":"portal-user_info-22.01.2018","node":"JEwfXRPHQSWjPn4L4U6AVQ","reason":{"type":"query_shard_exception","reason":"failed to find geo_shape field [location]","index_uuid":"nY7I_dOTSN-Edofxmk_P3Q","index":"portal-user_info-22.01.2018"}}]},"status":400}
		at org.elasticsearch.client.RestClient$1.completed(RestClient.java:357) ~[elasticsearch-rest-client-6.1.1.jar:6.1.1]
		at org.elasticsearch.client.RestClient$1.completed(RestClient.java:346) ~[elasticsearch-rest-client-6.1.1.jar:6.1.1]
		at org.apache.http.concurrent.BasicFuture.completed(BasicFuture.java:123) ~[httpcore-4.4.8.jar:4.4.8]
		at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.responseCompleted(DefaultClientExchangeHandlerImpl.java:181) ~[httpasyncclient-4.1.3.jar:4.1.3]
		at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.processResponse(HttpAsyncRequestExecutor.java:436) ~[httpcore-nio-4.4.5.jar:4.4.5]
		at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.inputReady(HttpAsyncRequestExecutor.java:326) ~[httpcore-nio-4.4.5.jar:4.4.5]
		at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:265) ~[httpcore-nio-4.4.5.jar:4.4.5]
		at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81) ~[httpasyncclient-4.1.3.jar:4.1.3]
		at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39) ~[httpasyncclient-4.1.3.jar:4.1.3]
		at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:114) ~[httpcore-nio-4.4.5.jar:4.4.5]
		at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162) ~[httpcore-nio-4.4.5.jar:4.4.5]
		at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337) ~[httpcore-nio-4.4.5.jar:4.4.5]
		at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315) ~[httpcore-nio-4.4.5.jar:4.4.5]
		at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276) ~[httpcore-nio-4.4.5.jar:4.4.5]
		at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104) ~[httpcore-nio-4.4.5.jar:4.4.5]
		at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:588) ~[httpcore-nio-4.4.5.jar:4.4.5]
		... 1 common frames omitted
```

---

<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:** [January 24, 2018, 12:53pm UTC](https://discuss.elastic.co/t/elasticsearch-java-searching-with-the-help-of-location-geopoint/116866/4 "2018-01-24T12:53:23Z")

</div>

geoShape Query works on shapes AFAIK [https://www.elastic.co/guide/en/elasticsearch/reference/6.1/geo-shape.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.1/geo-shape.html)

---

<div class="post-metadata">

**Author:** ![Nikita\_Krasnov](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@Nikita\_Krasnov](https://discuss.elastic.co/u/Nikita_Krasnov)\
**Post date:** [January 24, 2018, 1:39pm UTC](https://discuss.elastic.co/t/elasticsearch-java-searching-with-the-help-of-location-geopoint/116866/5 "2018-01-24T13:39:17Z")

</div>

As I understant for GeoPoint I have to use   
QueryBuilders.geoBoundingBoxQuery(), but I haven't find example of implementation.  
Can you give an example?

---

<div class="post-metadata">

**Author:** ![Nikita\_Krasnov](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@Nikita\_Krasnov](https://discuss.elastic.co/u/Nikita_Krasnov)\
**Post date:** [January 24, 2018, 2:15pm UTC](https://discuss.elastic.co/t/elasticsearch-java-searching-with-the-help-of-location-geopoint/116866/6 "2018-01-24T14:15:15Z")

</div>

What type of QueryBuilders I have to use for searching only with one location parameters(lat, lon) of type GeoPoint ?

---

<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:** [January 24, 2018, 3:36pm UTC](https://discuss.elastic.co/t/elasticsearch-java-searching-with-the-help-of-location-geopoint/116866/7 "2018-01-24T15:36:10Z")

</div>

[https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-query-builders.html#\_geo\_queries](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-query-builders.html#_geo_queries)

geoBoundingBoxQuery  
is one of them indeed: [https://artifacts.elastic.co/javadoc/org/elasticsearch/elasticsearch/6.1.2/org/elasticsearch/index/query/QueryBuilders.html#geoBoundingBoxQuery-java.lang.String-](https://artifacts.elastic.co/javadoc/org/elasticsearch/elasticsearch/6.1.2/org/elasticsearch/index/query/QueryBuilders.html#geoBoundingBoxQuery-java.lang.String-)

An example of this: [https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-geo-queries.html#java-query-dsl-geo-bounding-box-query](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-geo-queries.html#java-query-dsl-geo-bounding-box-query)

```auto
geoBoundingBoxQuery("pin.location")                          
    .setCorners(40.73, -74.1,                                
                40.717, -73.99);                             

```

---

<div class="post-metadata">

**Author:** ![Nikita\_Krasnov](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@Nikita\_Krasnov](https://discuss.elastic.co/u/Nikita_Krasnov)\
**Post date:** [January 25, 2018, 8:04am UTC](https://discuss.elastic.co/t/elasticsearch-java-searching-with-the-help-of-location-geopoint/116866/8 "2018-01-25T08:04:35Z")

</div>

But, if I need to search for logs having only one GeoPoint... In geoBoundingBoxQuery, I have to put 2 points. If I use the same coordinates for 2 points, I get an error: "top cannot be the same as bottom: "  
How I can search having only one GeoPoint?

---

<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:** [January 25, 2018, 8:35am UTC](https://discuss.elastic.co/t/elasticsearch-java-searching-with-the-help-of-location-geopoint/116866/9 "2018-01-25T08:35:41Z")

</div>

If you scroll the documentation a bit, you'll see:

[https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-geo-queries.html#java-query-dsl-geo-distance-query](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-geo-queries.html#java-query-dsl-geo-distance-query)

---

<div class="post-metadata">

**Author:** ![Nikita\_Krasnov](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@Nikita\_Krasnov](https://discuss.elastic.co/u/Nikita_Krasnov)\
**Post date:** [January 25, 2018, 9:16am UTC](https://discuss.elastic.co/t/elasticsearch-java-searching-with-the-help-of-location-geopoint/116866/10 "2018-01-25T09:16:55Z")

</div>

Ok, I think method geoDistanceQuery will work  
But right know (when I using this method) I get an error when try to find by geo location:

```
Suppressed: org.elasticsearch.client.ResponseException: method [GET], host [http://192.168.3.43:9200], URI [/_search?typed_keys=true&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&search_type=query_then_fetch&batched_reduce_size=512], status line [HTTP/1.1 400 Bad Request]
{"error":{"root_cause":[{"type":"query_shard_exception","reason":"failed to find geo_point field [location]","index_uuid":"mXFRna9FRm2_1p9mzT4LeA","index":".kibana"},{"type":"query_shard_exception","reason":"failed to find geo_point field [location]","index_uuid":"X-M1F-ZbT-SvWK8Bhzw3UQ","index":"portal-logs-24.01.2018"},{"type":"query_shard_exception","reason":"failed to find geo_point field [location]","index_uuid":"8B7M5hXLQt6WArUk1YzRug","index":"portal-logs-25.01.2018"},

```

And I think, it's due to incorrect saving of GeoPoint. I've added the print screen of kibana behind. It's how my GeoPoint is saved. And I have added the code also.  
What I am doing wrong during saving process?

---

<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:** [January 25, 2018, 9:33am UTC](https://discuss.elastic.co/t/elasticsearch-java-searching-with-the-help-of-location-geopoint/116866/11 "2018-01-25T09:33:38Z")

</div>

> [@Nikita\_Krasnov](#):
>
> And I think, it's due to incorrect saving of GeoPoint.

Yeah probably `location` is not a `geo_point` in your mapping.  
Check your mapping with `GET indexname/_mapping`

---

<div class="post-metadata">

**Author:** ![Nikita\_Krasnov](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@Nikita\_Krasnov](https://discuss.elastic.co/u/Nikita_Krasnov)\
**Post date:** [January 25, 2018, 10:37am UTC](https://discuss.elastic.co/t/elasticsearch-java-searching-with-the-help-of-location-geopoint/116866/12 "2018-01-25T10:37:47Z")

</div>

Result is

```
 "location": {
            "properties": {
              "lat": {
                "type": "float"
              },
              "lon": {
                "type": "float"
              }
            }
          }

```

But, how properly save GeoPoint? O maybe my json for saving is incorrect...  
For saving I used two types of jsons and both save incorrect.

```
{
location": "13.500544, 52.530286"
}

{
"location":{
"lat":13.400544,
"lon":52.530286
}
}
```

---

<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:** [January 25, 2018, 11:20am UTC](https://discuss.elastic.co/t/elasticsearch-java-searching-with-the-help-of-location-geopoint/116866/13 "2018-01-25T11:20:45Z")

</div>

That's what I said. Your mapping is incorrect. Fix your mapping first.

So:

DELETE the index  
PUT the new index with a correct mapping  
Index your documents

---

<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:** [February 22, 2018, 11:21am UTC](https://discuss.elastic.co/t/elasticsearch-java-searching-with-the-help-of-location-geopoint/116866/14 "2018-02-22T11:21:12Z")

</div>

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