# Java search for lat/long fields

**URL:** <https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287>\
**Category:** Elasticsearch\
**Created:** [January 10, 2013, 2:53am UTC](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287 "2013-01-10T02:53:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [January 10, 2013, 2:53am UTC](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287/1 "2013-01-10T02:53:00Z")

</div>

Hi,

I have a quite a few documents like this that are indexed in elasticsearch  
db (attached is just one for an example):

{

```
"took": 28,

"timed_out": false,

"_shards": {

    "total": 5,

    "successful": 5,

    "failed": 0

},

"hits": {

    "total": 694,

    "max_score": 1,

    "hits": [

        {

            "_index": "asset_index",

            "_type": "Asset",

            "_id": "4",

            "_score": 1,

            "_source": {

                "_id": 4,

                "className": "com.tycoint.eams.mongodb.AssetDB",

                "name": "FCC_SRV02",

                "serialNo": "Service Tag: 5S2HB2S\nExpress Service Tag: 

```

12581131348",

```
                "description": "Meridian Server Node 2 (Dell PowerEdge 

```

R710)",

```
                "location": {

                    "latitude": 5,

                    "longitude": 5

                },

                "address": {

                    "countryCode": "AU",

                    "state": "VIC",

                    "city": "Melbourne",

                    "postcode": "",

                    "street": "FCC",

                    "street2": "",

                    "detail": ""

                },

                "properties": {

                    "K1X3X15": "20121109",

                    "K2X1X1": "10.10.10.11",

                    "K1X3X14": "",

                    "K1X3X13": "",

                    "K2X1X2": "",

                    "K1X3X12": "02 8972 5897",

                    "K2X1X3": "FCC",

                    "K2X1X4": "10.0",

                    "K2X1X5": "",

                    "K1X3X16": "1 Year",

                    "K1X3X8": "",

                    "K1X1X1": "FCC",

                    "K1X2X5": "",

                    "K1X2X4": "FCC",

                    "K1X1X2": "PLD-DRG-A-6112",

                    "K1X3X7": "Dell PowerEdge R710",

                    "K1X1X3": "",

                    "K1X3X9": "Current",

                    "K1X2X1": "Server",

                    "K1X3X11": "Zac Cochrane",

                    "K1X3X10": "DELL Aust Pty Ltd",

                    "K1X2X3": "FCC",

                    "K1X2X2": "FCC",

                    "K3X1X4": "",

                    "K3X1X3": "",

                    "K3X1X2": "",

                    "K3X1X1": "",

                    "K1X3X5": "Physical Key: 

```

YTF2W-KFJ3P-3W447-8K3J4-42VVQ\nVirtual Key: 39C2W-H7QWQ-DBH43-37MJ8-HPD2G",

```
                    "K1X3X6": "",

                    "K1X3X3": "IM0004-D-0003 Hardware Architectural 

```

Design Document \nIM0004-D-0004 Peninsula link Device List",

```
                    "K1X3X4": "IM0004-PLG-SP-I-0036 Dell PowerEdge 

```

R710",

```
                    "K1X3X1": "20111109",

                    "K1X3X2": "Meridian Cluster Node2"

                },

                "productId": 4,

                "assetCategoryId": 0

            }

        }

    ]

}

```

As you can see my location field has two sub fields latitude/longitude  
(under \_source).

I would like to retrieve all documents with the distance 500m from location  
[1, 1] using Java.

I am trying to play with this code:

SearchRequestBuilder srb =  
client.prepareSearch("asset\_index").setTypes("Asset").setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());

srb.setFilter(FilterBuilders.geoDistanceRangeFilter("filter1").lat(1).lon(1).geoDistance(  
GeoDistance.PLANE));

How can I specify the distance 500 m from lat/long[1/1]?

Any suggestions?

Regards,

Janusz

--

---

<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 10, 2013, 1:43pm UTC](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287/2 "2013-01-10T13:43:48Z")

</div>

Hi Janusz,

Have a look here:

> <https://github.com/elasticsearchfr/elasticsearch-java-tests/blob/master/src/test/java/org/elasticsearchfr/tests/ES004GeoDistanceFilterTest.java#L48>

SearchRequestBuilder srb =  
node.client().prepareSearch("es004index").setTypes("type1")  
.setQuery(QueryBuilders.matchAllQuery())

.setFilter(FilterBuilders.geoDistanceFilter("location").distance("0.5km").point(5,  
5));

Caution: you defined a geo point with latitude and longitude fields. But you  
have to use lat and lng instead.

HTH  
David.

Le 10 janvier 2013 à 03:53, JD [jdalecki@tycoint.com](mailto:jdalecki@tycoint.com) a écrit :

> Hi,
> 
> I have a quite a few documents like this that are indexed in elasticsearch db  
> (attached is just one for an example):
> 
> {
> 
> ```
> "took": 28,
> 
> "timed_out": false,
> 
> "_shards": {
> 
> "total": 5,
> 
> "successful": 5,
> 
> "failed": 0
> 
> },
> 
> "hits": {
> 
> "total": 694,
> 
> "max_score": 1,
> 
> "hits": [
> 
> {
> 
> "_index": "asset_index",
> 
> "_type": "Asset",
> 
> "_id": "4",
> 
> "_score": 1,
> 
> "_source": {
> 
> "_id": 4,
> 
> "className": "com.tycoint.eams.mongodb.AssetDB",
> 
> "name": "FCC_SRV02",
> 
> "serialNo": "Service Tag: 5S2HB2S\nExpress Service Tag:
> 
> ```
> 
> 12581131348",
> 
> ```
> "description": "Meridian Server Node 2 (Dell PowerEdge
> 
> ```
> 
> R710)",
> 
> ```
> "location": {
> 
> "latitude": 5,
> 
> "longitude": 5
> 
> },
> 
> "address": {
> 
> "countryCode": "AU",
> 
> "state": "VIC",
> 
> "city": "Melbourne",
> 
> "postcode": "",
> 
> "street": "FCC",
> 
> "street2": "",
> 
> "detail": ""
> 
> },
> 
> "properties": {
> 
> "K1X3X15": "20121109",
> 
> "K2X1X1": "10.10.10.11",
> 
> "K1X3X14": "",
> 
> "K1X3X13": "",
> 
> "K2X1X2": "",
> 
> "K1X3X12": "02 8972 5897",
> 
> "K2X1X3": "FCC",
> 
> "K2X1X4": "10.0",
> 
> "K2X1X5": "",
> 
> "K1X3X16": "1 Year",
> 
> "K1X3X8": "",
> 
> "K1X1X1": "FCC",
> 
> "K1X2X5": "",
> 
> "K1X2X4": "FCC",
> 
> "K1X1X2": "PLD-DRG-A-6112",
> 
> "K1X3X7": "Dell PowerEdge R710",
> 
> "K1X1X3": "",
> 
> "K1X3X9": "Current",
> 
> "K1X2X1": "Server",
> 
> "K1X3X11": "Zac Cochrane",
> 
> "K1X3X10": "DELL Aust Pty Ltd",
> 
> "K1X2X3": "FCC",
> 
> "K1X2X2": "FCC",
> 
> "K3X1X4": "",
> 
> "K3X1X3": "",
> 
> "K3X1X2": "",
> 
> "K3X1X1": "",
> 
> "K1X3X5": "Physical Key:
> 
> ```
> 
> YTF2W-KFJ3P-3W447-8K3J4-42VVQ\nVirtual Key: 39C2W-H7QWQ-DBH43-37MJ8-HPD2G",
> 
> ```
> "K1X3X6": "",
> 
> "K1X3X3": "IM0004-D-0003 Hardware Architectural
> 
> ```
> 
> Design Document \nIM0004-D-0004 Peninsula link Device List",
> 
> ```
> "K1X3X4": "IM0004-PLG-SP-I-0036 Dell PowerEdge R710",
> 
> "K1X3X1": "20111109",
> 
> "K1X3X2": "Meridian Cluster Node2"
> 
> },
> 
> "productId": 4,
> 
> "assetCategoryId": 0
> 
> }
> 
> }
> 
> ]
> 
> }
> 
> ```
> 
> As you can see my location field has two sub fields latitude/longitude (under  
> \_source).
> 
> I would like to retrieve all documents with the distance 500m from location  
> [1, 1] using Java.
> 
> I am trying to play with this code:  
> SearchRequestBuilder srb =  
> client.prepareSearch("asset\_index").setTypes("Asset").setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());
> 
> ```
> srb.setFilter(FilterBuilders.geoDistanceRangeFilter("filter1").lat(1).lon(1).geoDistance(GeoDistance.PLANE));
> 
> ```
> 
> How can I specify the distance 500 m from lat/long[1/1]?
> 
> Any suggestions?
> 
> Regards,
> 
> Janusz
> 
> --

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [January 10, 2013, 11:47pm UTC](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287/3 "2013-01-10T23:47:16Z")

</div>

Hi,

Thanks for the reply David.

I have tried the way you have suggested, but I am hitting now another  
problem.

I am using mongoDB river plugin that indexes my Asset objects into  
elasticsearch (when I create them). The problem is that "location" is not  
correctly mapped as “geo\_point”. When I execute  
“[http://localhost:9200/asset\_index/Asset/\_mapping?pretty=true”](http://localhost:9200/asset_index/Asset/_mapping?pretty=true%E2%80%9D) command it  
gives me this (I have removed irrelevant properties as there are quite a  
few – the relevant is “location” – it does not have type, but it has field  
“dynamic” set to true):

{

```
"Asset": {

    "properties": {

        "address": {

            "dynamic": "true",

            "properties": {

                "city": {

                    "type": "string"

                },

                "countryCode": {

                    "type": "string"

                },

                "state": {

                    "type": "string"

                },

                "street": {

                    "type": "string"

                }

            }

        },

        "location": {

            "dynamic": "true",

            "properties": {

                "latitude": {

                    "type": "double"

                },

                "longitude": {

                    "type": "double"

                }

            }

        }

                            }

            }

```

}

Is there any way to fix the mapping problem either in mongodb river or by  
executing some elasticsearch command to change location to be of type  
“geo\_point”?

Regards,

Janusz

On Thursday, January 10, 2013 1:53:00 PM UTC+11, JD wrote:

> Hi,
> 
> I have a quite a few documents like this that are indexed in elasticsearch  
> db (attached is just one for an example):
> 
> {
> 
> ```
> "took": 28,
> 
> "timed_out": false,
> 
> "_shards": {
> 
> "total": 5,
> 
> "successful": 5,
> 
> "failed": 0
> 
> },
> 
> "hits": {
> 
> "total": 694,
> 
> "max_score": 1,
> 
> "hits": [
> 
> {
> 
> "_index": "asset_index",
> 
> "_type": "Asset",
> 
> "_id": "4",
> 
> "_score": 1,
> 
> "_source": {
> 
> "_id": 4,
> 
> "className": "com.tycoint.eams.mongodb.AssetDB",
> 
> "name": "FCC_SRV02",
> 
> "serialNo": "Service Tag: 5S2HB2S\nExpress Service 
> 
> ```
> 
> Tag: 12581131348",
> 
> ```
> "description": "Meridian Server Node 2 (Dell PowerEdge 
> 
> ```
> 
> R710)",
> 
> ```
> "location": {
> 
> "latitude": 5,
> 
> "longitude": 5
> 
> },
> 
> "address": {
> 
> "countryCode": "AU",
> 
> "state": "VIC",
> 
> "city": "Melbourne",
> 
> "postcode": "",
> 
> "street": "FCC",
> 
> "street2": "",
> 
> "detail": ""
> 
> },
> 
> "properties": {
> 
> "K1X3X15": "20121109",
> 
> "K2X1X1": "10.10.10.11",
> 
> "K1X3X14": "",
> 
> "K1X3X13": "",
> 
> "K2X1X2": "",
> 
> "K1X3X12": "02 8972 5897",
> 
> "K2X1X3": "FCC",
> 
> "K2X1X4": "10.0",
> 
> "K2X1X5": "",
> 
> "K1X3X16": "1 Year",
> 
> "K1X3X8": "",
> 
> "K1X1X1": "FCC",
> 
> "K1X2X5": "",
> 
> "K1X2X4": "FCC",
> 
> "K1X1X2": "PLD-DRG-A-6112",
> 
> "K1X3X7": "Dell PowerEdge R710",
> 
> "K1X1X3": "",
> 
> "K1X3X9": "Current",
> 
> "K1X2X1": "Server",
> 
> "K1X3X11": "Zac Cochrane",
> 
> "K1X3X10": "DELL Aust Pty Ltd",
> 
> "K1X2X3": "FCC",
> 
> "K1X2X2": "FCC",
> 
> "K3X1X4": "",
> 
> "K3X1X3": "",
> 
> "K3X1X2": "",
> 
> "K3X1X1": "",
> 
> "K1X3X5": "Physical Key: 
> 
> ```
> 
> YTF2W-KFJ3P-3W447-8K3J4-42VVQ\nVirtual Key: 39C2W-H7QWQ-DBH43-37MJ8-HPD2G",
> 
> ```
> "K1X3X6": "",
> 
> "K1X3X3": "IM0004-D-0003 Hardware Architectural 
> 
> ```
> 
> Design Document \nIM0004-D-0004 Peninsula link Device List",
> 
> ```
> "K1X3X4": "IM0004-PLG-SP-I-0036 Dell PowerEdge 
> 
> ```
> 
> R710",
> 
> ```
> "K1X3X1": "20111109",
> 
> "K1X3X2": "Meridian Cluster Node2"
> 
> },
> 
> "productId": 4,
> 
> "assetCategoryId": 0
> 
> }
> 
> }
> 
> ]
> 
> }
> 
> ```
> 
> As you can see my location field has two sub fields latitude/longitude  
> (under \_source).
> 
> I would like to retrieve all documents with the distance 500m from  
> location [1, 1] using Java.
> 
> I am trying to play with this code:
> 
> SearchRequestBuilder srb =  
> client.prepareSearch("asset\_index").setTypes("Asset").setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());
> 
> srb.setFilter(FilterBuilders.geoDistanceRangeFilter("filter1").lat(1).lon(1).geoDistance(  
> GeoDistance.PLANE));
> 
> How can I specify the distance 500 m from lat/long[1/1]?
> 
> Any suggestions?
> 
> Regards,
> 
> Janusz

--

---

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [January 11, 2013, 2:29am UTC](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287/4 "2013-01-11T02:29:06Z")

</div>

I forgot to attach the exception I am getting after issuing :  
SearchRequestBuilder srb =  
client.prepareSearch("asset\_index").setTypes("Asset")

.setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());  
DistanceBoundingCheck bc = GeoDistance  
.distanceBoundingCheck(5, 5, 1, DistanceUnit.KILOMETERS);

srb.setFilter(FilterBuilders.geoDistanceFilter("location").distance("0.5km").point(5,  
5));  
SearchResponse response = srb.execute().actionGet();

... anf then I get the following exception:  
_org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to  
execute phase [query], total failure; shardFailures  
{[kIywvG8VQ5C32AnbutXL-g][asset\_index][1]:  
SearchParseException[[asset\_index][1]:  
query[ConstantScore(NotDeleted(_:_))],from[-1],size[-1]: Parse Failure  
[Failed to parse source  
[{"query":{"match\_all":{}},"filter":{"geo\_distance":{"location":[5.0,5.0],"distance":"0.5km"}}}]]];  
nested: QueryParsingException[[asset\_index] failed to find geo\_point field  
[location]]; }{[kIywvG8VQ5C32AnbutXL-g][asset\_index][2]:  
SearchParseException[[asset\_index][2]:  
query[ConstantScore(NotDeleted(_:_))],from[-1],size[-1]: Parse Failure  
[Failed to parse source  
[{"query":{"match\_all":{}},"filter":{"geo\_distance":{"location":[5.0,5.0],"distance":"0.5km"}}}]]];  
nested: QueryParsingException[[asset\_index] failed to find geo\_point field  
[location]]; }_

- at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:260)
- 
- at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onFailure(TransportSearchTypeAction.java:213)
- 
- at  
org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:144)
- 
- at  
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:80)
- 
- at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:205)
- 
- at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:192)
- 
- at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:178)
- 
- at  
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
- 
- at  
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
- 
- at java.lang.Thread.run(Thread.java:662)\*

On Thursday, January 10, 2013 1:53:00 PM UTC+11, JD wrote:

> Hi,
> 
> I have a quite a few documents like this that are indexed in elasticsearch  
> db (attached is just one for an example):
> 
> {
> 
> ```
> "took": 28,
> 
> "timed_out": false,
> 
> "_shards": {
> 
> "total": 5,
> 
> "successful": 5,
> 
> "failed": 0
> 
> },
> 
> "hits": {
> 
> "total": 694,
> 
> "max_score": 1,
> 
> "hits": [
> 
> {
> 
> "_index": "asset_index",
> 
> "_type": "Asset",
> 
> "_id": "4",
> 
> "_score": 1,
> 
> "_source": {
> 
> "_id": 4,
> 
> "className": "com.tycoint.eams.mongodb.AssetDB",
> 
> "name": "FCC_SRV02",
> 
> "serialNo": "Service Tag: 5S2HB2S\nExpress Service 
> 
> ```
> 
> Tag: 12581131348",
> 
> ```
> "description": "Meridian Server Node 2 (Dell PowerEdge 
> 
> ```
> 
> R710)",
> 
> ```
> "location": {
> 
> "latitude": 5,
> 
> "longitude": 5
> 
> },
> 
> "address": {
> 
> "countryCode": "AU",
> 
> "state": "VIC",
> 
> "city": "Melbourne",
> 
> "postcode": "",
> 
> "street": "FCC",
> 
> "street2": "",
> 
> "detail": ""
> 
> },
> 
> "properties": {
> 
> "K1X3X15": "20121109",
> 
> "K2X1X1": "10.10.10.11",
> 
> "K1X3X14": "",
> 
> "K1X3X13": "",
> 
> "K2X1X2": "",
> 
> "K1X3X12": "02 8972 5897",
> 
> "K2X1X3": "FCC",
> 
> "K2X1X4": "10.0",
> 
> "K2X1X5": "",
> 
> "K1X3X16": "1 Year",
> 
> "K1X3X8": "",
> 
> "K1X1X1": "FCC",
> 
> "K1X2X5": "",
> 
> "K1X2X4": "FCC",
> 
> "K1X1X2": "PLD-DRG-A-6112",
> 
> "K1X3X7": "Dell PowerEdge R710",
> 
> "K1X1X3": "",
> 
> "K1X3X9": "Current",
> 
> "K1X2X1": "Server",
> 
> "K1X3X11": "Zac Cochrane",
> 
> "K1X3X10": "DELL Aust Pty Ltd",
> 
> "K1X2X3": "FCC",
> 
> "K1X2X2": "FCC",
> 
> "K3X1X4": "",
> 
> "K3X1X3": "",
> 
> "K3X1X2": "",
> 
> "K3X1X1": "",
> 
> "K1X3X5": "Physical Key: 
> 
> ```
> 
> YTF2W-KFJ3P-3W447-8K3J4-42VVQ\nVirtual Key: 39C2W-H7QWQ-DBH43-37MJ8-HPD2G",
> 
> ```
> "K1X3X6": "",
> 
> "K1X3X3": "IM0004-D-0003 Hardware Architectural 
> 
> ```
> 
> Design Document \nIM0004-D-0004 Peninsula link Device List",
> 
> ```
> "K1X3X4": "IM0004-PLG-SP-I-0036 Dell PowerEdge 
> 
> ```
> 
> R710",
> 
> ```
> "K1X3X1": "20111109",
> 
> "K1X3X2": "Meridian Cluster Node2"
> 
> },
> 
> "productId": 4,
> 
> "assetCategoryId": 0
> 
> }
> 
> }
> 
> ]
> 
> }
> 
> ```
> 
> As you can see my location field has two sub fields latitude/longitude  
> (under \_source).
> 
> I would like to retrieve all documents with the distance 500m from  
> location [1, 1] using Java.
> 
> I am trying to play with this code:
> 
> SearchRequestBuilder srb =  
> client.prepareSearch("asset\_index").setTypes("Asset").setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());
> 
> srb.setFilter(FilterBuilders.geoDistanceRangeFilter("filter1").lat(1).lon(1).geoDistance(  
> GeoDistance.PLANE));
> 
> How can I specify the distance 500 m from lat/long[1/1]?
> 
> Any suggestions?
> 
> Regards,
> 
> Janusz

--

---

<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 11, 2013, 9:10am UTC](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287/5 "2013-01-11T09:10:43Z")

</div>

You have to define your mapping prior to create the river.  
In this mapping, define that location is a geo point type.

BUT, you have to modify latitude / longitude before indexing it.  
If you are using a river (couchDb for example), you can modify your document  
using scripts:  
[https://github.com/elasticsearch/elasticsearch-river-couchdb/blob/master/README.md#script-filters](https://github.com/elasticsearch/elasticsearch-river-couchdb/blob/master/README.md#script-filters)  
[https://github.com/elasticsearch/elasticsearch-river-couchdb/blob/master/README.md#script-filters](https://github.com/elasticsearch/elasticsearch-river-couchdb/blob/master/README.md#script-filters)

David

Le 11 janvier 2013 à 03:29, JD [jdalecki@tycoint.com](mailto:jdalecki@tycoint.com) a écrit :

> I forgot to attach the exception I am getting after issuing :  
> SearchRequestBuilder srb =  
> client.prepareSearch("asset\_index").setTypes("Asset")
> 
> ```
> .setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());
> DistanceBoundingCheck bc = GeoDistance
> .distanceBoundingCheck(5, 5, 1, DistanceUnit.KILOMETERS);
> 
> srb.setFilter(FilterBuilders.geoDistanceFilter("location").distance("0.5km").point(5,
> 
> ```
> 
> 5));  
> SearchResponse response = srb.execute().actionGet();
> 
> ... anf then I get the following exception:  
> org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to  
> execute phase [query], total failure; shardFailures  
> {[kIywvG8VQ5C32AnbutXL-g][asset\_index][1]:  
> SearchParseException[[asset\_index][1]:  
> query[ConstantScore(NotDeleted(_:_))],from[-1],size[-1]: Parse Failure [Failed  
> to parse source  
> [{"query":{"match\_all":{}},"filter":{"geo\_distance":{"location":[5.0,5.0],"distance":"0.5km"}}}]]];  
> nested: QueryParsingException[[asset\_index] failed to find geo\_point field  
> [location]]; }{[kIywvG8VQ5C32AnbutXL-g][asset\_index][2]:  
> SearchParseException[[asset\_index][2]:  
> query[ConstantScore(NotDeleted(_:_))],from[-1],size[-1]: Parse Failure [Failed  
> to parse source  
> [{"query":{"match\_all":{}},"filter":{"geo\_distance":{"location":[5.0,5.0],"distance":"0.5km"}}}]]];  
> nested: QueryParsingException[[asset\_index] failed to find geo\_point field  
> [location]]; }  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:260)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onFailure(TransportSearchTypeAction.java:213)  
> at  
> org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:144)  
> at  
> org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:80)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:205)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:192)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:178)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
> at java.lang.Thread.run(Thread.java:662)
> 
> On Thursday, January 10, 2013 1:53:00 PM UTC+11, JD wrote:
> 
> > > 
> > 
> > Hi,
> > 
> > I have a quite a few documents like this that are indexed in  
> > elasticsearch db (attached is just one for an example):
> > 
> > {
> > 
> > ```
> > "took": 28,
> > 
> > "timed_out": false,
> > 
> > "_shards": {
> > 
> > "total": 5,
> > 
> > "successful": 5,
> > 
> > "failed": 0
> > 
> > },
> > 
> > "hits": {
> > 
> > "total": 694,
> > 
> > "max_score": 1,
> > 
> > "hits": [
> > 
> > {
> > 
> > "_index": "asset_index",
> > 
> > "_type": "Asset",
> > 
> > "_id": "4",
> > 
> > "_score": 1,
> > 
> > "_source": {
> > 
> > "_id": 4,
> > 
> > "className": "com.tycoint.eams.mongodb.AssetDB",
> > 
> > "name": "FCC_SRV02",
> > 
> > "serialNo": "Service Tag: 5S2HB2S\nExpress Service
> > 
> > ```
> > 
> > Tag: 12581131348",
> > 
> > ```
> > "description": "Meridian Server Node 2 (Dell
> > 
> > ```
> > 
> > PowerEdge R710)",
> > 
> > ```
> > "location": {
> > 
> > "latitude": 5,
> > 
> > "longitude": 5
> > 
> > },
> > 
> > "address": {
> > 
> > "countryCode": "AU",
> > 
> > "state": "VIC",
> > 
> > "city": "Melbourne",
> > 
> > "postcode": "",
> > 
> > "street": "FCC",
> > 
> > "street2": "",
> > 
> > "detail": ""
> > 
> > },
> > 
> > "properties": {
> > 
> > "K1X3X15": "20121109",
> > 
> > "K2X1X1": "10.10.10.11",
> > 
> > "K1X3X14": "",
> > 
> > "K1X3X13": "",
> > 
> > "K2X1X2": "",
> > 
> > "K1X3X12": "02 8972 5897",
> > 
> > "K2X1X3": "FCC",
> > 
> > "K2X1X4": "10.0",
> > 
> > "K2X1X5": "",
> > 
> > "K1X3X16": "1 Year",
> > 
> > "K1X3X8": "",
> > 
> > "K1X1X1": "FCC",
> > 
> > "K1X2X5": "",
> > 
> > "K1X2X4": "FCC",
> > 
> > "K1X1X2": "PLD-DRG-A-6112",
> > 
> > "K1X3X7": "Dell PowerEdge R710",
> > 
> > "K1X1X3": "",
> > 
> > "K1X3X9": "Current",
> > 
> > "K1X2X1": "Server",
> > 
> > "K1X3X11": "Zac Cochrane",
> > 
> > "K1X3X10": "DELL Aust Pty Ltd",
> > 
> > "K1X2X3": "FCC",
> > 
> > "K1X2X2": "FCC",
> > 
> > "K3X1X4": "",
> > 
> > "K3X1X3": "",
> > 
> > "K3X1X2": "",
> > 
> > "K3X1X1": "",
> > 
> > "K1X3X5": "Physical Key:
> > 
> > ```
> > 
> > YTF2W-KFJ3P-3W447-8K3J4-42VVQ\nVirtual Key: 39C2W-H7QWQ-DBH43-37MJ8-HPD2G",
> > 
> > ```
> > "K1X3X6": "",
> > 
> > "K1X3X3": "IM0004-D-0003 Hardware Architectural
> > 
> > ```
> > 
> > Design Document \nIM0004-D-0004 Peninsula link Device List",
> > 
> > ```
> > "K1X3X4": "IM0004-PLG-SP-I-0036 Dell PowerEdge
> > 
> > ```
> > 
> > R710",
> > 
> > ```
> > "K1X3X1": "20111109",
> > 
> > "K1X3X2": "Meridian Cluster Node2"
> > 
> > },
> > 
> > "productId": 4,
> > 
> > "assetCategoryId": 0
> > 
> > }
> > 
> > }
> > 
> > ]
> > 
> > }
> > 
> > ```
> > 
> > As you can see my location field has two sub fields latitude/longitude  
> > (under \_source).
> > 
> > I would like to retrieve all documents with the distance 500m from  
> > location [1, 1] using Java.
> > 
> > I am trying to play with this code:  
> > SearchRequestBuilder srb =  
> > client.prepareSearch("asset\_index").setTypes("Asset").setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());
> > 
> > ```
> > srb.setFilter(FilterBuilders.geoDistanceRangeFilter("filter1").lat(1).lon(1).geoDistance(GeoDistance.PLANE));
> > 
> > ```
> > 
> > How can I specify the distance 500 m from lat/long[1/1]?
> > 
> > Any suggestions?
> > 
> > Regards,
> > 
> > Janusz
> > 
> > >
> 
> --

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [January 11, 2013, 10:14am UTC](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287/6 "2013-01-11T10:14:36Z")

</div>

Hi David,

I thought mapping is created automatically when first time I create an  
object in MongoDB which is then indexed into elasticsearch? How do I create  
mapping before running river?

What do you mean by “BUT, you have to modify latitude / longitude before  
indexing it”?

Thanks for your help,

Regards,  
Janusz

On Thursday, January 10, 2013 1:53:00 PM UTC+11, JD wrote:

> Hi,
> 
> I have a quite a few documents like this that are indexed in elasticsearch  
> db (attached is just one for an example):
> 
> {
> 
> ```
> "took": 28,
> 
> "timed_out": false,
> 
> "_shards": {
> 
> "total": 5,
> 
> "successful": 5,
> 
> "failed": 0
> 
> },
> 
> "hits": {
> 
> "total": 694,
> 
> "max_score": 1,
> 
> "hits": [
> 
> {
> 
> "_index": "asset_index",
> 
> "_type": "Asset",
> 
> "_id": "4",
> 
> "_score": 1,
> 
> "_source": {
> 
> "_id": 4,
> 
> "className": "com.tycoint.eams.mongodb.AssetDB",
> 
> "name": "FCC_SRV02",
> 
> "serialNo": "Service Tag: 5S2HB2S\nExpress Service 
> 
> ```
> 
> Tag: 12581131348",
> 
> ```
> "description": "Meridian Server Node 2 (Dell PowerEdge 
> 
> ```
> 
> R710)",
> 
> ```
> "location": {
> 
> "latitude": 5,
> 
> "longitude": 5
> 
> },
> 
> "address": {
> 
> "countryCode": "AU",
> 
> "state": "VIC",
> 
> "city": "Melbourne",
> 
> "postcode": "",
> 
> "street": "FCC",
> 
> "street2": "",
> 
> "detail": ""
> 
> },
> 
> "properties": {
> 
> "K1X3X15": "20121109",
> 
> "K2X1X1": "10.10.10.11",
> 
> "K1X3X14": "",
> 
> "K1X3X13": "",
> 
> "K2X1X2": "",
> 
> "K1X3X12": "02 8972 5897",
> 
> "K2X1X3": "FCC",
> 
> "K2X1X4": "10.0",
> 
> "K2X1X5": "",
> 
> "K1X3X16": "1 Year",
> 
> "K1X3X8": "",
> 
> "K1X1X1": "FCC",
> 
> "K1X2X5": "",
> 
> "K1X2X4": "FCC",
> 
> "K1X1X2": "PLD-DRG-A-6112",
> 
> "K1X3X7": "Dell PowerEdge R710",
> 
> "K1X1X3": "",
> 
> "K1X3X9": "Current",
> 
> "K1X2X1": "Server",
> 
> "K1X3X11": "Zac Cochrane",
> 
> "K1X3X10": "DELL Aust Pty Ltd",
> 
> "K1X2X3": "FCC",
> 
> "K1X2X2": "FCC",
> 
> "K3X1X4": "",
> 
> "K3X1X3": "",
> 
> "K3X1X2": "",
> 
> "K3X1X1": "",
> 
> "K1X3X5": "Physical Key: 
> 
> ```
> 
> YTF2W-KFJ3P-3W447-8K3J4-42VVQ\nVirtual Key: 39C2W-H7QWQ-DBH43-37MJ8-HPD2G",
> 
> ```
> "K1X3X6": "",
> 
> "K1X3X3": "IM0004-D-0003 Hardware Architectural 
> 
> ```
> 
> Design Document \nIM0004-D-0004 Peninsula link Device List",
> 
> ```
> "K1X3X4": "IM0004-PLG-SP-I-0036 Dell PowerEdge 
> 
> ```
> 
> R710",
> 
> ```
> "K1X3X1": "20111109",
> 
> "K1X3X2": "Meridian Cluster Node2"
> 
> },
> 
> "productId": 4,
> 
> "assetCategoryId": 0
> 
> }
> 
> }
> 
> ]
> 
> }
> 
> ```
> 
> As you can see my location field has two sub fields latitude/longitude  
> (under \_source).
> 
> I would like to retrieve all documents with the distance 500m from  
> location [1, 1] using Java.
> 
> I am trying to play with this code:
> 
> SearchRequestBuilder srb =  
> client.prepareSearch("asset\_index").setTypes("Asset").setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());
> 
> srb.setFilter(FilterBuilders.geoDistanceRangeFilter("filter1").lat(1).lon(1).geoDistance(  
> GeoDistance.PLANE));
> 
> How can I specify the distance 500 m from lat/long[1/1]?
> 
> Any suggestions?
> 
> Regards,
> 
> Janusz

--

---

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [January 12, 2013, 2:25am UTC](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287/7 "2013-01-12T02:25:54Z")

</div>

Hi,

I have created mapping using the code attached in _mappin\_code.java_ as  
David suggested. I have also attached to my post my mapping retrieved from  
elasticsearch using command - [http://localhost:9200/asset\_index/\_mapping(my\_mapping.txt)](http://localhost:9200/asset_index/_mapping(my_mapping.txt)) and one Asset document that we use (one\_asset.txt).

When I execute this code:

SearchRequestBuilder srb = client.prepareSearch("asset\_index").setTypes(  
"Asset") .setSearchType(SearchType._DEFAULT_).setQuery(QueryBuilders.\*  
matchAllQuery\*());

```
  DistanceBoundingCheck *bc* = GeoDistance

      .*distanceBoundingCheck*(5, 5, 1, DistanceUnit.*KILOMETERS*);

  srb.setFilter(FilterBuilders.*geoDistanceFilter*("location").distance(

```

"0.5km").point(5, 5));

```
  SearchResponse response = srb.execute().actionGet();

 SearchHit[] docs = response.getHits().getHits();

```

_"docs"_ variable displays under debugger this text:

org.eclipse.debug.core.DebugException: com.sun.jdi.ClassNotLoadedException:  
Type has not been loaded occurred while retrieving component type of array.

This is probably the last issue that I have with my “prove of concept”  
stage. I need to be able to search for location and I know I am close, but  
still not getting there.

Dave in your last reply what exactly do you mean by "you have to modify  
latitude / longitude before indexing it". Do I need to do anything else  
apart from manually creating mapping for location to be geo\_point?

Regards,

Janusz

On Thursday, January 10, 2013 1:53:00 PM UTC+11, JD wrote:

> Hi,
> 
> I have a quite a few documents like this that are indexed in elasticsearch  
> db (attached is just one for an example):
> 
> {
> 
> ```
> "took": 28,
> 
> "timed_out": false,
> 
> "_shards": {
> 
> "total": 5,
> 
> "successful": 5,
> 
> "failed": 0
> 
> },
> 
> "hits": {
> 
> "total": 694,
> 
> "max_score": 1,
> 
> "hits": [
> 
> {
> 
> "_index": "asset_index",
> 
> "_type": "Asset",
> 
> "_id": "4",
> 
> "_score": 1,
> 
> "_source": {
> 
> "_id": 4,
> 
> "className": "com.tycoint.eams.mongodb.AssetDB",
> 
> "name": "FCC_SRV02",
> 
> "serialNo": "Service Tag: 5S2HB2S\nExpress Service 
> 
> ```
> 
> Tag: 12581131348",
> 
> ```
> "description": "Meridian Server Node 2 (Dell PowerEdge 
> 
> ```
> 
> R710)",
> 
> ```
> "location": {
> 
> "latitude": 5,
> 
> "longitude": 5
> 
> },
> 
> "address": {
> 
> "countryCode": "AU",
> 
> "state": "VIC",
> 
> "city": "Melbourne",
> 
> "postcode": "",
> 
> "street": "FCC",
> 
> "street2": "",
> 
> "detail": ""
> 
> },
> 
> "properties": {
> 
> "K1X3X15": "20121109",
> 
> "K2X1X1": "10.10.10.11",
> 
> "K1X3X14": "",
> 
> "K1X3X13": "",
> 
> "K2X1X2": "",
> 
> "K1X3X12": "02 8972 5897",
> 
> "K2X1X3": "FCC",
> 
> "K2X1X4": "10.0",
> 
> "K2X1X5": "",
> 
> "K1X3X16": "1 Year",
> 
> "K1X3X8": "",
> 
> "K1X1X1": "FCC",
> 
> "K1X2X5": "",
> 
> "K1X2X4": "FCC",
> 
> "K1X1X2": "PLD-DRG-A-6112",
> 
> "K1X3X7": "Dell PowerEdge R710",
> 
> "K1X1X3": "",
> 
> "K1X3X9": "Current",
> 
> "K1X2X1": "Server",
> 
> "K1X3X11": "Zac Cochrane",
> 
> "K1X3X10": "DELL Aust Pty Ltd",
> 
> "K1X2X3": "FCC",
> 
> "K1X2X2": "FCC",
> 
> "K3X1X4": "",
> 
> "K3X1X3": "",
> 
> "K3X1X2": "",
> 
> "K3X1X1": "",
> 
> "K1X3X5": "Physical Key: 
> 
> ```
> 
> YTF2W-KFJ3P-3W447-8K3J4-42VVQ\nVirtual Key: 39C2W-H7QWQ-DBH43-37MJ8-HPD2G",
> 
> ```
> "K1X3X6": "",
> 
> "K1X3X3": "IM0004-D-0003 Hardware Architectural 
> 
> ```
> 
> Design Document \nIM0004-D-0004 Peninsula link Device List",
> 
> ```
> "K1X3X4": "IM0004-PLG-SP-I-0036 Dell PowerEdge 
> 
> ```
> 
> R710",
> 
> ```
> "K1X3X1": "20111109",
> 
> "K1X3X2": "Meridian Cluster Node2"
> 
> },
> 
> "productId": 4,
> 
> "assetCategoryId": 0
> 
> }
> 
> }
> 
> ]
> 
> }
> 
> ```
> 
> As you can see my location field has two sub fields latitude/longitude  
> (under \_source).
> 
> I would like to retrieve all documents with the distance 500m from  
> location [1, 1] using Java.
> 
> I am trying to play with this code:
> 
> SearchRequestBuilder srb =  
> client.prepareSearch("asset\_index").setTypes("Asset").setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());
> 
> srb.setFilter(FilterBuilders.geoDistanceRangeFilter("filter1").lat(1).lon(1).geoDistance(  
> GeoDistance.PLANE));
> 
> How can I specify the distance 500 m from lat/long[1/1]?
> 
> Any suggestions?
> 
> Regards,
> 
> Janusz

--

---

<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 12, 2013, 6:31am UTC](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287/8 "2013-01-12T06:31:50Z")

</div>

I was meaning that latitude must be renamed to lat and longitude to lng.

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

Le 11 janv. 2013 à 11:14, JD [jdalecki@tycoint.com](mailto:jdalecki@tycoint.com) a écrit :

Hi David,  
I thought mapping is created automatically when first time I create an object in MongoDB which is then indexed into elasticsearch? How do I create mapping before running river?  
What do you mean by “BUT, you have to modify latitude / longitude before indexing it”?  
Thanks for your help,  
Regards,  
Janusz

On Thursday, January 10, 2013 1:53:00 PM UTC+11, JD wrote:

> Hi,  
> I have a quite a few documents like this that are indexed in elasticsearch db (attached is just one for an example):  
> {  
> "took": 28,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 5,  
> "successful": 5,  
> "failed": 0  
> },  
> "hits": {  
> "total": 694,  
> "max\_score": 1,  
> "hits": [  
> {  
> "\_index": "asset\_index",  
> "\_type": "Asset",  
> "\_id": "4",  
> "\_score": 1,  
> "\_source": {  
> "\_id": 4,  
> "className": "com.tycoint.eams.mongodb.AssetDB",  
> "name": "FCC\_SRV02",  
> "serialNo": "Service Tag: 5S2HB2S\nExpress Service Tag: 12581131348",  
> "description": "Meridian Server Node 2 (Dell PowerEdge R710)",  
> "location": {  
> "latitude": 5,  
> "longitude": 5  
> },  
> "address": {  
> "countryCode": "AU",  
> "state": "VIC",  
> "city": "Melbourne",  
> "postcode": "",  
> "street": "FCC",  
> "street2": "",  
> "detail": ""  
> },  
> "properties": {  
> "K1X3X15": "20121109",  
> "K2X1X1": "10.10.10.11",  
> "K1X3X14": "",  
> "K1X3X13": "",  
> "K2X1X2": "",  
> "K1X3X12": "02 8972 5897",  
> "K2X1X3": "FCC",  
> "K2X1X4": "10.0",  
> "K2X1X5": "",  
> "K1X3X16": "1 Year",  
> "K1X3X8": "",  
> "K1X1X1": "FCC",  
> "K1X2X5": "",  
> "K1X2X4": "FCC",  
> "K1X1X2": "PLD-DRG-A-6112",  
> "K1X3X7": "Dell PowerEdge R710",  
> "K1X1X3": "",  
> "K1X3X9": "Current",  
> "K1X2X1": "Server",  
> "K1X3X11": "Zac Cochrane",  
> "K1X3X10": "DELL Aust Pty Ltd",  
> "K1X2X3": "FCC",  
> "K1X2X2": "FCC",  
> "K3X1X4": "",  
> "K3X1X3": "",  
> "K3X1X2": "",  
> "K3X1X1": "",  
> "K1X3X5": "Physical Key: YTF2W-KFJ3P-3W447-8K3J4-42VVQ\nVirtual Key: 39C2W-H7QWQ-DBH43-37MJ8-HPD2G",  
> "K1X3X6": "",  
> "K1X3X3": "IM0004-D-0003 Hardware Architectural Design Document \nIM0004-D-0004 Peninsula link Device List",  
> "K1X3X4": "IM0004-PLG-SP-I-0036 Dell PowerEdge R710",  
> "K1X3X1": "20111109",  
> "K1X3X2": "Meridian Cluster Node2"  
> },  
> "productId": 4,  
> "assetCategoryId": 0  
> }  
> }  
> ]  
> }
> 
> As you can see my location field has two sub fields latitude/longitude (under \_source).  
> I would like to retrieve all documents with the distance 500m from location [1, 1] using Java.  
> I am trying to play with this code:  
> SearchRequestBuilder srb = client.prepareSearch("asset\_index").setTypes("Asset").setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());  
> srb.setFilter(FilterBuilders.geoDistanceRangeFilter("filter1").lat(1).lon(1).geoDistance(GeoDistance.PLANE));  
> How can I specify the distance 500 m from lat/long[1/1]?  
> Any suggestions?  
> Regards,  
> Janusz

--

--

---

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [January 12, 2013, 6:41am UTC](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287/9 "2013-01-12T06:41:34Z")

</div>

Thanks. Yep it works.  
However we have got legacy software where it is not possible to change  
those two keywords - I have changed them just for testing purpose and it  
does work.  
Is there a way to configure those keywords to be latitude and longitude in  
elasticsearch or that's the way it is and it must be lat/lon.  
Regards,  
Janusz

On Thursday, January 10, 2013 1:53:00 PM UTC+11, JD wrote:

> Hi,
> 
> I have a quite a few documents like this that are indexed in elasticsearch  
> db (attached is just one for an example):
> 
> {
> 
> ```
> "took": 28,
> 
> "timed_out": false,
> 
> "_shards": {
> 
> "total": 5,
> 
> "successful": 5,
> 
> "failed": 0
> 
> },
> 
> "hits": {
> 
> "total": 694,
> 
> "max_score": 1,
> 
> "hits": [
> 
> {
> 
> "_index": "asset_index",
> 
> "_type": "Asset",
> 
> "_id": "4",
> 
> "_score": 1,
> 
> "_source": {
> 
> "_id": 4,
> 
> "className": "com.tycoint.eams.mongodb.AssetDB",
> 
> "name": "FCC_SRV02",
> 
> "serialNo": "Service Tag: 5S2HB2S\nExpress Service 
> 
> ```
> 
> Tag: 12581131348",
> 
> ```
> "description": "Meridian Server Node 2 (Dell PowerEdge 
> 
> ```
> 
> R710)",
> 
> ```
> "location": {
> 
> "latitude": 5,
> 
> "longitude": 5
> 
> },
> 
> "address": {
> 
> "countryCode": "AU",
> 
> "state": "VIC",
> 
> "city": "Melbourne",
> 
> "postcode": "",
> 
> "street": "FCC",
> 
> "street2": "",
> 
> "detail": ""
> 
> },
> 
> "properties": {
> 
> "K1X3X15": "20121109",
> 
> "K2X1X1": "10.10.10.11",
> 
> "K1X3X14": "",
> 
> "K1X3X13": "",
> 
> "K2X1X2": "",
> 
> "K1X3X12": "02 8972 5897",
> 
> "K2X1X3": "FCC",
> 
> "K2X1X4": "10.0",
> 
> "K2X1X5": "",
> 
> "K1X3X16": "1 Year",
> 
> "K1X3X8": "",
> 
> "K1X1X1": "FCC",
> 
> "K1X2X5": "",
> 
> "K1X2X4": "FCC",
> 
> "K1X1X2": "PLD-DRG-A-6112",
> 
> "K1X3X7": "Dell PowerEdge R710",
> 
> "K1X1X3": "",
> 
> "K1X3X9": "Current",
> 
> "K1X2X1": "Server",
> 
> "K1X3X11": "Zac Cochrane",
> 
> "K1X3X10": "DELL Aust Pty Ltd",
> 
> "K1X2X3": "FCC",
> 
> "K1X2X2": "FCC",
> 
> "K3X1X4": "",
> 
> "K3X1X3": "",
> 
> "K3X1X2": "",
> 
> "K3X1X1": "",
> 
> "K1X3X5": "Physical Key: 
> 
> ```
> 
> YTF2W-KFJ3P-3W447-8K3J4-42VVQ\nVirtual Key: 39C2W-H7QWQ-DBH43-37MJ8-HPD2G",
> 
> ```
> "K1X3X6": "",
> 
> "K1X3X3": "IM0004-D-0003 Hardware Architectural 
> 
> ```
> 
> Design Document \nIM0004-D-0004 Peninsula link Device List",
> 
> ```
> "K1X3X4": "IM0004-PLG-SP-I-0036 Dell PowerEdge 
> 
> ```
> 
> R710",
> 
> ```
> "K1X3X1": "20111109",
> 
> "K1X3X2": "Meridian Cluster Node2"
> 
> },
> 
> "productId": 4,
> 
> "assetCategoryId": 0
> 
> }
> 
> }
> 
> ]
> 
> }
> 
> ```
> 
> As you can see my location field has two sub fields latitude/longitude  
> (under \_source).
> 
> I would like to retrieve all documents with the distance 500m from  
> location [1, 1] using Java.
> 
> I am trying to play with this code:
> 
> SearchRequestBuilder srb =  
> client.prepareSearch("asset\_index").setTypes("Asset").setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());
> 
> srb.setFilter(FilterBuilders.geoDistanceRangeFilter("filter1").lat(1).lon(1).geoDistance(  
> GeoDistance.PLANE));
> 
> How can I specify the distance 500 m from lat/long[1/1]?
> 
> Any suggestions?
> 
> Regards,
> 
> Janusz

--

---

<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 12, 2013, 6:46am UTC](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287/10 "2013-01-12T06:46:09Z")

</div>

Nope, AFAIK. It would be probably doable in a next release.

But if I remember it well, you are using a river, aren't you?

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

Le 12 janv. 2013 à 07:41, JD [jdalecki@tycoint.com](mailto:jdalecki@tycoint.com) a écrit :

Thanks. Yep it works.  
However we have got legacy software where it is not possible to change those two keywords - I have changed them just for testing purpose and it does work.  
Is there a way to configure those keywords to be latitude and longitude in elasticsearch or that's the way it is and it must be lat/lon.  
Regards,  
Janusz

On Thursday, January 10, 2013 1:53:00 PM UTC+11, JD wrote:

> Hi,  
> I have a quite a few documents like this that are indexed in elasticsearch db (attached is just one for an example):  
> {  
> "took": 28,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 5,  
> "successful": 5,  
> "failed": 0  
> },  
> "hits": {  
> "total": 694,  
> "max\_score": 1,  
> "hits": [  
> {  
> "\_index": "asset\_index",  
> "\_type": "Asset",  
> "\_id": "4",  
> "\_score": 1,  
> "\_source": {  
> "\_id": 4,  
> "className": "com.tycoint.eams.mongodb.AssetDB",  
> "name": "FCC\_SRV02",  
> "serialNo": "Service Tag: 5S2HB2S\nExpress Service Tag: 12581131348",  
> "description": "Meridian Server Node 2 (Dell PowerEdge R710)",  
> "location": {  
> "latitude": 5,  
> "longitude": 5  
> },  
> "address": {  
> "countryCode": "AU",  
> "state": "VIC",  
> "city": "Melbourne",  
> "postcode": "",  
> "street": "FCC",  
> "street2": "",  
> "detail": ""  
> },  
> "properties": {  
> "K1X3X15": "20121109",  
> "K2X1X1": "10.10.10.11",  
> "K1X3X14": "",  
> "K1X3X13": "",  
> "K2X1X2": "",  
> "K1X3X12": "02 8972 5897",  
> "K2X1X3": "FCC",  
> "K2X1X4": "10.0",  
> "K2X1X5": "",  
> "K1X3X16": "1 Year",  
> "K1X3X8": "",  
> "K1X1X1": "FCC",  
> "K1X2X5": "",  
> "K1X2X4": "FCC",  
> "K1X1X2": "PLD-DRG-A-6112",  
> "K1X3X7": "Dell PowerEdge R710",  
> "K1X1X3": "",  
> "K1X3X9": "Current",  
> "K1X2X1": "Server",  
> "K1X3X11": "Zac Cochrane",  
> "K1X3X10": "DELL Aust Pty Ltd",  
> "K1X2X3": "FCC",  
> "K1X2X2": "FCC",  
> "K3X1X4": "",  
> "K3X1X3": "",  
> "K3X1X2": "",  
> "K3X1X1": "",  
> "K1X3X5": "Physical Key: YTF2W-KFJ3P-3W447-8K3J4-42VVQ\nVirtual Key: 39C2W-H7QWQ-DBH43-37MJ8-HPD2G",  
> "K1X3X6": "",  
> "K1X3X3": "IM0004-D-0003 Hardware Architectural Design Document \nIM0004-D-0004 Peninsula link Device List",  
> "K1X3X4": "IM0004-PLG-SP-I-0036 Dell PowerEdge R710",  
> "K1X3X1": "20111109",  
> "K1X3X2": "Meridian Cluster Node2"  
> },  
> "productId": 4,  
> "assetCategoryId": 0  
> }  
> }  
> ]  
> }
> 
> As you can see my location field has two sub fields latitude/longitude (under \_source).  
> I would like to retrieve all documents with the distance 500m from location [1, 1] using Java.  
> I am trying to play with this code:  
> SearchRequestBuilder srb = client.prepareSearch("asset\_index").setTypes("Asset").setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());  
> srb.setFilter(FilterBuilders.geoDistanceRangeFilter("filter1").lat(1).lon(1).geoDistance(GeoDistance.PLANE));  
> How can I specify the distance 500 m from lat/long[1/1]?  
> Any suggestions?  
> Regards,  
> Janusz

--

--

---

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [January 12, 2013, 6:48am UTC](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287/11 "2013-01-12T06:48:16Z")

</div>

Yep. I am using mongoDB river.  
Regards,  
Janusz

On Thursday, January 10, 2013 1:53:00 PM UTC+11, JD wrote:

> Hi,
> 
> I have a quite a few documents like this that are indexed in elasticsearch  
> db (attached is just one for an example):
> 
> {
> 
> ```
> "took": 28,
> 
> "timed_out": false,
> 
> "_shards": {
> 
> "total": 5,
> 
> "successful": 5,
> 
> "failed": 0
> 
> },
> 
> "hits": {
> 
> "total": 694,
> 
> "max_score": 1,
> 
> "hits": [
> 
> {
> 
> "_index": "asset_index",
> 
> "_type": "Asset",
> 
> "_id": "4",
> 
> "_score": 1,
> 
> "_source": {
> 
> "_id": 4,
> 
> "className": "com.tycoint.eams.mongodb.AssetDB",
> 
> "name": "FCC_SRV02",
> 
> "serialNo": "Service Tag: 5S2HB2S\nExpress Service 
> 
> ```
> 
> Tag: 12581131348",
> 
> ```
> "description": "Meridian Server Node 2 (Dell PowerEdge 
> 
> ```
> 
> R710)",
> 
> ```
> "location": {
> 
> "latitude": 5,
> 
> "longitude": 5
> 
> },
> 
> "address": {
> 
> "countryCode": "AU",
> 
> "state": "VIC",
> 
> "city": "Melbourne",
> 
> "postcode": "",
> 
> "street": "FCC",
> 
> "street2": "",
> 
> "detail": ""
> 
> },
> 
> "properties": {
> 
> "K1X3X15": "20121109",
> 
> "K2X1X1": "10.10.10.11",
> 
> "K1X3X14": "",
> 
> "K1X3X13": "",
> 
> "K2X1X2": "",
> 
> "K1X3X12": "02 8972 5897",
> 
> "K2X1X3": "FCC",
> 
> "K2X1X4": "10.0",
> 
> "K2X1X5": "",
> 
> "K1X3X16": "1 Year",
> 
> "K1X3X8": "",
> 
> "K1X1X1": "FCC",
> 
> "K1X2X5": "",
> 
> "K1X2X4": "FCC",
> 
> "K1X1X2": "PLD-DRG-A-6112",
> 
> "K1X3X7": "Dell PowerEdge R710",
> 
> "K1X1X3": "",
> 
> "K1X3X9": "Current",
> 
> "K1X2X1": "Server",
> 
> "K1X3X11": "Zac Cochrane",
> 
> "K1X3X10": "DELL Aust Pty Ltd",
> 
> "K1X2X3": "FCC",
> 
> "K1X2X2": "FCC",
> 
> "K3X1X4": "",
> 
> "K3X1X3": "",
> 
> "K3X1X2": "",
> 
> "K3X1X1": "",
> 
> "K1X3X5": "Physical Key: 
> 
> ```
> 
> YTF2W-KFJ3P-3W447-8K3J4-42VVQ\nVirtual Key: 39C2W-H7QWQ-DBH43-37MJ8-HPD2G",
> 
> ```
> "K1X3X6": "",
> 
> "K1X3X3": "IM0004-D-0003 Hardware Architectural 
> 
> ```
> 
> Design Document \nIM0004-D-0004 Peninsula link Device List",
> 
> ```
> "K1X3X4": "IM0004-PLG-SP-I-0036 Dell PowerEdge 
> 
> ```
> 
> R710",
> 
> ```
> "K1X3X1": "20111109",
> 
> "K1X3X2": "Meridian Cluster Node2"
> 
> },
> 
> "productId": 4,
> 
> "assetCategoryId": 0
> 
> }
> 
> }
> 
> ]
> 
> }
> 
> ```
> 
> As you can see my location field has two sub fields latitude/longitude  
> (under \_source).
> 
> I would like to retrieve all documents with the distance 500m from  
> location [1, 1] using Java.
> 
> I am trying to play with this code:
> 
> SearchRequestBuilder srb =  
> client.prepareSearch("asset\_index").setTypes("Asset").setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());
> 
> srb.setFilter(FilterBuilders.geoDistanceRangeFilter("filter1").lat(1).lon(1).geoDistance(  
> GeoDistance.PLANE));
> 
> How can I specify the distance 500 m from lat/long[1/1]?
> 
> Any suggestions?
> 
> Regards,
> 
> Janusz

--

---

<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 12, 2013, 6:59am UTC](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287/12 "2013-01-12T06:59:30Z")

</div>

Perhaps, you could fork the mongodb river and add the same script function that exist in couchDb river (I did not checked if it already exists).

If you don't want to modify it, I can suggest not to use the river and fetch content from mongo then inject it from your side.

I prefer the 1st option. 🙂

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

Le 12 janv. 2013 à 07:48, JD [jdalecki@tycoint.com](mailto:jdalecki@tycoint.com) a écrit :

Yep. I am using mongoDB river.  
Regards,  
Janusz

On Thursday, January 10, 2013 1:53:00 PM UTC+11, JD wrote:

> Hi,  
> I have a quite a few documents like this that are indexed in elasticsearch db (attached is just one for an example):  
> {  
> "took": 28,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 5,  
> "successful": 5,  
> "failed": 0  
> },  
> "hits": {  
> "total": 694,  
> "max\_score": 1,  
> "hits": [  
> {  
> "\_index": "asset\_index",  
> "\_type": "Asset",  
> "\_id": "4",  
> "\_score": 1,  
> "\_source": {  
> "\_id": 4,  
> "className": "com.tycoint.eams.mongodb.AssetDB",  
> "name": "FCC\_SRV02",  
> "serialNo": "Service Tag: 5S2HB2S\nExpress Service Tag: 12581131348",  
> "description": "Meridian Server Node 2 (Dell PowerEdge R710)",  
> "location": {  
> "latitude": 5,  
> "longitude": 5  
> },  
> "address": {  
> "countryCode": "AU",  
> "state": "VIC",  
> "city": "Melbourne",  
> "postcode": "",  
> "street": "FCC",  
> "street2": "",  
> "detail": ""  
> },  
> "properties": {  
> "K1X3X15": "20121109",  
> "K2X1X1": "10.10.10.11",  
> "K1X3X14": "",  
> "K1X3X13": "",  
> "K2X1X2": "",  
> "K1X3X12": "02 8972 5897",  
> "K2X1X3": "FCC",  
> "K2X1X4": "10.0",  
> "K2X1X5": "",  
> "K1X3X16": "1 Year",  
> "K1X3X8": "",  
> "K1X1X1": "FCC",  
> "K1X2X5": "",  
> "K1X2X4": "FCC",  
> "K1X1X2": "PLD-DRG-A-6112",  
> "K1X3X7": "Dell PowerEdge R710",  
> "K1X1X3": "",  
> "K1X3X9": "Current",  
> "K1X2X1": "Server",  
> "K1X3X11": "Zac Cochrane",  
> "K1X3X10": "DELL Aust Pty Ltd",  
> "K1X2X3": "FCC",  
> "K1X2X2": "FCC",  
> "K3X1X4": "",  
> "K3X1X3": "",  
> "K3X1X2": "",  
> "K3X1X1": "",  
> "K1X3X5": "Physical Key: YTF2W-KFJ3P-3W447-8K3J4-42VVQ\nVirtual Key: 39C2W-H7QWQ-DBH43-37MJ8-HPD2G",  
> "K1X3X6": "",  
> "K1X3X3": "IM0004-D-0003 Hardware Architectural Design Document \nIM0004-D-0004 Peninsula link Device List",  
> "K1X3X4": "IM0004-PLG-SP-I-0036 Dell PowerEdge R710",  
> "K1X3X1": "20111109",  
> "K1X3X2": "Meridian Cluster Node2"  
> },  
> "productId": 4,  
> "assetCategoryId": 0  
> }  
> }  
> ]  
> }
> 
> As you can see my location field has two sub fields latitude/longitude (under \_source).  
> I would like to retrieve all documents with the distance 500m from location [1, 1] using Java.  
> I am trying to play with this code:  
> SearchRequestBuilder srb = client.prepareSearch("asset\_index").setTypes("Asset").setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());  
> srb.setFilter(FilterBuilders.geoDistanceRangeFilter("filter1").lat(1).lon(1).geoDistance(GeoDistance.PLANE));  
> How can I specify the distance 500 m from lat/long[1/1]?  
> Any suggestions?  
> Regards,  
> Janusz  
> --

--

---

<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 12, 2013, 11:09am UTC](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287/13 "2013-01-12T11:09:37Z")

</div>

Ok. I double checked and scripts are already there in mongo river. Just read the  
Wiki: [Home · richardwilly98/elasticsearch-river-mongodb Wiki · GitHub](https://github.com/richardwilly98/elasticsearch-river-mongodb/wiki)  
[https://github.com/richardwilly98/elasticsearch-river-mongodb/wiki](https://github.com/richardwilly98/elasticsearch-river-mongodb/wiki) to see how  
to set it up.

HTH  
David.

Le 12 janvier 2013 à 07:59, David Pilato [david@pilato.fr](mailto:david@pilato.fr) a écrit :

> Perhaps, you could fork the mongodb river and add the same script function  
> that exist in couchDb river (I did not checked if it already exists).
> 
> If you don't want to modify it, I can suggest not to use the river and fetch  
> content from mongo then inject it from your side.
> 
> I prefer the 1st option. 🙂
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 12 janv. 2013 à 07:48, JD \< [jdalecki@tycoint.com](mailto:jdalecki@tycoint.com)  
> [mailto:jdalecki@tycoint.com](mailto:jdalecki@tycoint.com) \> a écrit :
> 
> Yep. I am using mongoDB river.  
> Regards,  
> Janusz
> 
> On Thursday, January 10, 2013 1:53:00 PM UTC+11, JD wrote:
> 
> > > 
> > 
> > Hi,
> > 
> > I have a quite a few documents like this that are indexed in  
> > elasticsearch db (attached is just one for an example):
> > 
> > {
> > 
> > ```
> > "took": 28,
> > 
> > "timed_out": false,
> > 
> > "_shards": {
> > 
> > "total": 5,
> > 
> > "successful": 5,
> > 
> > "failed": 0
> > 
> > },
> > 
> > "hits": {
> > 
> > "total": 694,
> > 
> > "max_score": 1,
> > 
> > "hits": [
> > 
> > {
> > 
> > "_index": "asset_index",
> > 
> > "_type": "Asset",
> > 
> > "_id": "4",
> > 
> > "_score": 1,
> > 
> > "_source": {
> > 
> > "_id": 4,
> > 
> > "className": "com.tycoint.eams.mongodb.AssetDB",
> > 
> > "name": "FCC_SRV02",
> > 
> > "serialNo": "Service Tag: 5S2HB2S\nExpress Service
> > 
> > ```
> > 
> > Tag: 12581131348",
> > 
> > ```
> > "description": "Meridian Server Node 2 (Dell
> > 
> > ```
> > 
> > PowerEdge R710)",
> > 
> > ```
> > "location": {
> > 
> > "latitude": 5,
> > 
> > "longitude": 5
> > 
> > },
> > 
> > "address": {
> > 
> > "countryCode": "AU",
> > 
> > "state": "VIC",
> > 
> > "city": "Melbourne",
> > 
> > "postcode": "",
> > 
> > "street": "FCC",
> > 
> > "street2": "",
> > 
> > "detail": ""
> > 
> > },
> > 
> > "properties": {
> > 
> > "K1X3X15": "20121109",
> > 
> > "K2X1X1": "10.10.10.11",
> > 
> > "K1X3X14": "",
> > 
> > "K1X3X13": "",
> > 
> > "K2X1X2": "",
> > 
> > "K1X3X12": "02 8972 5897",
> > 
> > "K2X1X3": "FCC",
> > 
> > "K2X1X4": "10.0",
> > 
> > "K2X1X5": "",
> > 
> > "K1X3X16": "1 Year",
> > 
> > "K1X3X8": "",
> > 
> > "K1X1X1": "FCC",
> > 
> > "K1X2X5": "",
> > 
> > "K1X2X4": "FCC",
> > 
> > "K1X1X2": "PLD-DRG-A-6112",
> > 
> > "K1X3X7": "Dell PowerEdge R710",
> > 
> > "K1X1X3": "",
> > 
> > "K1X3X9": "Current",
> > 
> > "K1X2X1": "Server",
> > 
> > "K1X3X11": "Zac Cochrane",
> > 
> > "K1X3X10": "DELL Aust Pty Ltd",
> > 
> > "K1X2X3": "FCC",
> > 
> > "K1X2X2": "FCC",
> > 
> > "K3X1X4": "",
> > 
> > "K3X1X3": "",
> > 
> > "K3X1X2": "",
> > 
> > "K3X1X1": "",
> > 
> > "K1X3X5": "Physical Key:
> > 
> > ```
> > 
> > YTF2W-KFJ3P-3W447-8K3J4-42VVQ\nVirtual Key: 39C2W-H7QWQ-DBH43-37MJ8-HPD2G",
> > 
> > ```
> > "K1X3X6": "",
> > 
> > "K1X3X3": "IM0004-D-0003 Hardware Architectural
> > 
> > ```
> > 
> > Design Document \nIM0004-D-0004 Peninsula link Device List",
> > 
> > ```
> > "K1X3X4": "IM0004-PLG-SP-I-0036 Dell PowerEdge
> > 
> > ```
> > 
> > R710",
> > 
> > ```
> > "K1X3X1": "20111109",
> > 
> > "K1X3X2": "Meridian Cluster Node2"
> > 
> > },
> > 
> > "productId": 4,
> > 
> > "assetCategoryId": 0
> > 
> > }
> > 
> > }
> > 
> > ]
> > 
> > }
> > 
> > ```
> > 
> > As you can see my location field has two sub fields latitude/longitude  
> > (under \_source).
> > 
> > I would like to retrieve all documents with the distance 500m from  
> > location [1, 1] using Java.
> > 
> > I am trying to play with this code:  
> > SearchRequestBuilder srb =  
> > client.prepareSearch("asset\_index").setTypes("Asset").setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());
> > 
> > ```
> > srb.setFilter(FilterBuilders.geoDistanceRangeFilter("filter1").lat(1).lon(1).geoDistance(GeoDistance.PLANE));
> > 
> > ```
> > 
> > How can I specify the distance 500 m from lat/long[1/1]?
> > 
> > Any suggestions?
> > 
> > Regards,
> > 
> > Janusz
> > 
> > --
> > 
> > >
> 
> --

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [January 13, 2013, 1:48am UTC](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287/14 "2013-01-13T01:48:39Z")

</div>

Thanks a lot David,  
Regards,  
Janusz

On Thursday, January 10, 2013 1:53:00 PM UTC+11, JD wrote:

> Hi,
> 
> I have a quite a few documents like this that are indexed in elasticsearch  
> db (attached is just one for an example):
> 
> {
> 
> ```
> "took": 28,
> 
> "timed_out": false,
> 
> "_shards": {
> 
> "total": 5,
> 
> "successful": 5,
> 
> "failed": 0
> 
> },
> 
> "hits": {
> 
> "total": 694,
> 
> "max_score": 1,
> 
> "hits": [
> 
> {
> 
> "_index": "asset_index",
> 
> "_type": "Asset",
> 
> "_id": "4",
> 
> "_score": 1,
> 
> "_source": {
> 
> "_id": 4,
> 
> "className": "com.tycoint.eams.mongodb.AssetDB",
> 
> "name": "FCC_SRV02",
> 
> "serialNo": "Service Tag: 5S2HB2S\nExpress Service 
> 
> ```
> 
> Tag: 12581131348",
> 
> ```
> "description": "Meridian Server Node 2 (Dell PowerEdge 
> 
> ```
> 
> R710)",
> 
> ```
> "location": {
> 
> "latitude": 5,
> 
> "longitude": 5
> 
> },
> 
> "address": {
> 
> "countryCode": "AU",
> 
> "state": "VIC",
> 
> "city": "Melbourne",
> 
> "postcode": "",
> 
> "street": "FCC",
> 
> "street2": "",
> 
> "detail": ""
> 
> },
> 
> "properties": {
> 
> "K1X3X15": "20121109",
> 
> "K2X1X1": "10.10.10.11",
> 
> "K1X3X14": "",
> 
> "K1X3X13": "",
> 
> "K2X1X2": "",
> 
> "K1X3X12": "02 8972 5897",
> 
> "K2X1X3": "FCC",
> 
> "K2X1X4": "10.0",
> 
> "K2X1X5": "",
> 
> "K1X3X16": "1 Year",
> 
> "K1X3X8": "",
> 
> "K1X1X1": "FCC",
> 
> "K1X2X5": "",
> 
> "K1X2X4": "FCC",
> 
> "K1X1X2": "PLD-DRG-A-6112",
> 
> "K1X3X7": "Dell PowerEdge R710",
> 
> "K1X1X3": "",
> 
> "K1X3X9": "Current",
> 
> "K1X2X1": "Server",
> 
> "K1X3X11": "Zac Cochrane",
> 
> "K1X3X10": "DELL Aust Pty Ltd",
> 
> "K1X2X3": "FCC",
> 
> "K1X2X2": "FCC",
> 
> "K3X1X4": "",
> 
> "K3X1X3": "",
> 
> "K3X1X2": "",
> 
> "K3X1X1": "",
> 
> "K1X3X5": "Physical Key: 
> 
> ```
> 
> YTF2W-KFJ3P-3W447-8K3J4-42VVQ\nVirtual Key: 39C2W-H7QWQ-DBH43-37MJ8-HPD2G",
> 
> ```
> "K1X3X6": "",
> 
> "K1X3X3": "IM0004-D-0003 Hardware Architectural 
> 
> ```
> 
> Design Document \nIM0004-D-0004 Peninsula link Device List",
> 
> ```
> "K1X3X4": "IM0004-PLG-SP-I-0036 Dell PowerEdge 
> 
> ```
> 
> R710",
> 
> ```
> "K1X3X1": "20111109",
> 
> "K1X3X2": "Meridian Cluster Node2"
> 
> },
> 
> "productId": 4,
> 
> "assetCategoryId": 0
> 
> }
> 
> }
> 
> ]
> 
> }
> 
> ```
> 
> As you can see my location field has two sub fields latitude/longitude  
> (under \_source).
> 
> I would like to retrieve all documents with the distance 500m from  
> location [1, 1] using Java.
> 
> I am trying to play with this code:
> 
> SearchRequestBuilder srb =  
> client.prepareSearch("asset\_index").setTypes("Asset").setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());
> 
> srb.setFilter(FilterBuilders.geoDistanceRangeFilter("filter1").lat(1).lon(1).geoDistance(  
> GeoDistance.PLANE));
> 
> How can I specify the distance 500 m from lat/long[1/1]?
> 
> Any suggestions?
> 
> Regards,
> 
> Janusz

--

---

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [January 14, 2013, 6:32am UTC](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287/15 "2013-01-14T06:32:34Z")

</div>

David,  
Is it possible to use somehow Java Script to change mapping for location  
field to be of type geo\_point?  
Regards,  
Janusz

On Thursday, January 10, 2013 1:53:00 PM UTC+11, JD wrote:

> Hi,
> 
> I have a quite a few documents like this that are indexed in elasticsearch  
> db (attached is just one for an example):
> 
> {
> 
> ```
> "took": 28,
> 
> "timed_out": false,
> 
> "_shards": {
> 
> "total": 5,
> 
> "successful": 5,
> 
> "failed": 0
> 
> },
> 
> "hits": {
> 
> "total": 694,
> 
> "max_score": 1,
> 
> "hits": [
> 
> {
> 
> "_index": "asset_index",
> 
> "_type": "Asset",
> 
> "_id": "4",
> 
> "_score": 1,
> 
> "_source": {
> 
> "_id": 4,
> 
> "className": "com.tycoint.eams.mongodb.AssetDB",
> 
> "name": "FCC_SRV02",
> 
> "serialNo": "Service Tag: 5S2HB2S\nExpress Service 
> 
> ```
> 
> Tag: 12581131348",
> 
> ```
> "description": "Meridian Server Node 2 (Dell PowerEdge 
> 
> ```
> 
> R710)",
> 
> ```
> "location": {
> 
> "latitude": 5,
> 
> "longitude": 5
> 
> },
> 
> "address": {
> 
> "countryCode": "AU",
> 
> "state": "VIC",
> 
> "city": "Melbourne",
> 
> "postcode": "",
> 
> "street": "FCC",
> 
> "street2": "",
> 
> "detail": ""
> 
> },
> 
> "properties": {
> 
> "K1X3X15": "20121109",
> 
> "K2X1X1": "10.10.10.11",
> 
> "K1X3X14": "",
> 
> "K1X3X13": "",
> 
> "K2X1X2": "",
> 
> "K1X3X12": "02 8972 5897",
> 
> "K2X1X3": "FCC",
> 
> "K2X1X4": "10.0",
> 
> "K2X1X5": "",
> 
> "K1X3X16": "1 Year",
> 
> "K1X3X8": "",
> 
> "K1X1X1": "FCC",
> 
> "K1X2X5": "",
> 
> "K1X2X4": "FCC",
> 
> "K1X1X2": "PLD-DRG-A-6112",
> 
> "K1X3X7": "Dell PowerEdge R710",
> 
> "K1X1X3": "",
> 
> "K1X3X9": "Current",
> 
> "K1X2X1": "Server",
> 
> "K1X3X11": "Zac Cochrane",
> 
> "K1X3X10": "DELL Aust Pty Ltd",
> 
> "K1X2X3": "FCC",
> 
> "K1X2X2": "FCC",
> 
> "K3X1X4": "",
> 
> "K3X1X3": "",
> 
> "K3X1X2": "",
> 
> "K3X1X1": "",
> 
> "K1X3X5": "Physical Key: 
> 
> ```
> 
> YTF2W-KFJ3P-3W447-8K3J4-42VVQ\nVirtual Key: 39C2W-H7QWQ-DBH43-37MJ8-HPD2G",
> 
> ```
> "K1X3X6": "",
> 
> "K1X3X3": "IM0004-D-0003 Hardware Architectural 
> 
> ```
> 
> Design Document \nIM0004-D-0004 Peninsula link Device List",
> 
> ```
> "K1X3X4": "IM0004-PLG-SP-I-0036 Dell PowerEdge 
> 
> ```
> 
> R710",
> 
> ```
> "K1X3X1": "20111109",
> 
> "K1X3X2": "Meridian Cluster Node2"
> 
> },
> 
> "productId": 4,
> 
> "assetCategoryId": 0
> 
> }
> 
> }
> 
> ]
> 
> }
> 
> ```
> 
> As you can see my location field has two sub fields latitude/longitude  
> (under \_source).
> 
> I would like to retrieve all documents with the distance 500m from  
> location [1, 1] using Java.
> 
> I am trying to play with this code:
> 
> SearchRequestBuilder srb =  
> client.prepareSearch("asset\_index").setTypes("Asset").setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());
> 
> srb.setFilter(FilterBuilders.geoDistanceRangeFilter("filter1").lat(1).lon(1).geoDistance(  
> GeoDistance.PLANE));
> 
> How can I specify the distance 500 m from lat/long[1/1]?
> 
> Any suggestions?
> 
> Regards,
> 
> Janusz

--

---

<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 14, 2013, 7:14am UTC](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287/16 "2013-01-14T07:14:36Z")

</div>

No.

Let me say once again.

Send your mapping before creating the river.  
You can not change the mapping later.

HTH

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

Le 14 janv. 2013 à 07:32, JD [jdalecki@tycoint.com](mailto:jdalecki@tycoint.com) a écrit :

> David,  
> Is it possible to use somehow Java Script to change mapping for location field to be of type geo\_point?  
> Regards,  
> Janusz
> 
> On Thursday, January 10, 2013 1:53:00 PM UTC+11, JD wrote:
> 
> > Hi,  
> > I have a quite a few documents like this that are indexed in elasticsearch db (attached is just one for an example):  
> > {  
> > "took": 28,  
> > "timed\_out": false,  
> > "\_shards": {  
> > "total": 5,  
> > "successful": 5,  
> > "failed": 0  
> > },  
> > "hits": {  
> > "total": 694,  
> > "max\_score": 1,  
> > "hits": [  
> > {  
> > "\_index": "asset\_index",  
> > "\_type": "Asset",  
> > "\_id": "4",  
> > "\_score": 1,  
> > "\_source": {  
> > "\_id": 4,  
> > "className": "com.tycoint.eams.mongodb.AssetDB",  
> > "name": "FCC\_SRV02",  
> > "serialNo": "Service Tag: 5S2HB2S\nExpress Service Tag: 12581131348",  
> > "description": "Meridian Server Node 2 (Dell PowerEdge R710)",  
> > "location": {  
> > "latitude": 5,  
> > "longitude": 5  
> > },  
> > "address": {  
> > "countryCode": "AU",  
> > "state": "VIC",  
> > "city": "Melbourne",  
> > "postcode": "",  
> > "street": "FCC",  
> > "street2": "",  
> > "detail": ""  
> > },  
> > "properties": {  
> > "K1X3X15": "20121109",  
> > "K2X1X1": "10.10.10.11",  
> > "K1X3X14": "",  
> > "K1X3X13": "",  
> > "K2X1X2": "",  
> > "K1X3X12": "02 8972 5897",  
> > "K2X1X3": "FCC",  
> > "K2X1X4": "10.0",  
> > "K2X1X5": "",  
> > "K1X3X16": "1 Year",  
> > "K1X3X8": "",  
> > "K1X1X1": "FCC",  
> > "K1X2X5": "",  
> > "K1X2X4": "FCC",  
> > "K1X1X2": "PLD-DRG-A-6112",  
> > "K1X3X7": "Dell PowerEdge R710",  
> > "K1X1X3": "",  
> > "K1X3X9": "Current",  
> > "K1X2X1": "Server",  
> > "K1X3X11": "Zac Cochrane",  
> > "K1X3X10": "DELL Aust Pty Ltd",  
> > "K1X2X3": "FCC",  
> > "K1X2X2": "FCC",  
> > "K3X1X4": "",  
> > "K3X1X3": "",  
> > "K3X1X2": "",  
> > "K3X1X1": "",  
> > "K1X3X5": "Physical Key: YTF2W-KFJ3P-3W447-8K3J4-42VVQ\nVirtual Key: 39C2W-H7QWQ-DBH43-37MJ8-HPD2G",  
> > "K1X3X6": "",  
> > "K1X3X3": "IM0004-D-0003 Hardware Architectural Design Document \nIM0004-D-0004 Peninsula link Device List",  
> > "K1X3X4": "IM0004-PLG-SP-I-0036 Dell PowerEdge R710",  
> > "K1X3X1": "20111109",  
> > "K1X3X2": "Meridian Cluster Node2"  
> > },  
> > "productId": 4,  
> > "assetCategoryId": 0  
> > }  
> > }  
> > ]  
> > }
> > 
> > As you can see my location field has two sub fields latitude/longitude (under \_source).  
> > I would like to retrieve all documents with the distance 500m from location [1, 1] using Java.  
> > I am trying to play with this code:  
> > SearchRequestBuilder srb = client.prepareSearch("asset\_index").setTypes("Asset").setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());  
> > srb.setFilter(FilterBuilders.geoDistanceRangeFilter("filter1").lat(1).lon(1).geoDistance(GeoDistance.PLANE));  
> > How can I specify the distance 500 m from lat/long[1/1]?  
> > Any suggestions?  
> > Regards,  
> > Janusz
> 
> --

--

---

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [January 15, 2013, 1:53am UTC](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287/17 "2013-01-15T01:53:56Z")

</div>

Hi David,  
I think I am still missing something.  
When I try to create mapping before I create river for the collection Asset  
I get this exception:  
org.elasticsearch.indices.IndexMissingException: [asset\_index] missing  
at  
org.elasticsearch.cluster.metadata.MetaData.convertFromWildcards(MetaData.java:602)  
at  
org.elasticsearch.cluster.metadata.MetaData.concreteIndices(MetaData.java:514)  
at  
org.elasticsearch.cluster.metadata.MetaData.concreteIndices(MetaData.java:497)  
at  
org.elasticsearch.action.admin.indices.mapping.put.TransportPutMappingAction.doExecute(TransportPutMappingAction.java:74)  
at  
org.elasticsearch.action.admin.indices.mapping.put.TransportPutMappingAction.doExecute(TransportPutMappingAction.java:41)  
at  
org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:61)  
at  
org.elasticsearch.client.node.NodeIndicesAdminClient.execute(NodeIndicesAdminClient.java:72)  
at  
org.elasticsearch.client.support.AbstractIndicesAdminClient.putMapping(AbstractIndicesAdminClient.java:290)  
at  
org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder.doExecute(PutMappingRequestBuilder.java:109)  
at  
org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:62)  
at  
org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:57)  
at com.tycoint.eams.servlet.UploadXml.buildAssetMapping(UploadXml.java:147)  
at com.tycoint.eams.servlet.UploadXml.doPost(UploadXml.java:46)  
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)  
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)  
at  
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)  
at  
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)  
at  
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)  
at  
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)  
at  
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)  
at  
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)  
at  
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)  
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)  
at  
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)  
at  
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)  
at  
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)  
at  
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)  
at  
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)  
at  
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
at  
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
at java.lang.Thread.run(Thread.java:662)

When you say "send mapping before creating river" you mean to execute this  
code - is that right?:  
PutMappingResponse response = node.client().admin().indices()  
.preparePutMapping("asset\_index")  
.setType("Asset")  
.setSource(xbMapping)  
.execute().actionGet();  
Regards,  
Janusz

On Thursday, January 10, 2013 1:53:00 PM UTC+11, JD wrote:

> Hi,
> 
> I have a quite a few documents like this that are indexed in elasticsearch  
> db (attached is just one for an example):
> 
> {
> 
> ```
> "took": 28,
> 
> "timed_out": false,
> 
> "_shards": {
> 
> "total": 5,
> 
> "successful": 5,
> 
> "failed": 0
> 
> },
> 
> "hits": {
> 
> "total": 694,
> 
> "max_score": 1,
> 
> "hits": [
> 
> {
> 
> "_index": "asset_index",
> 
> "_type": "Asset",
> 
> "_id": "4",
> 
> "_score": 1,
> 
> "_source": {
> 
> "_id": 4,
> 
> "className": "com.tycoint.eams.mongodb.AssetDB",
> 
> "name": "FCC_SRV02",
> 
> "serialNo": "Service Tag: 5S2HB2S\nExpress Service 
> 
> ```
> 
> Tag: 12581131348",
> 
> ```
> "description": "Meridian Server Node 2 (Dell PowerEdge 
> 
> ```
> 
> R710)",
> 
> ```
> "location": {
> 
> "latitude": 5,
> 
> "longitude": 5
> 
> },
> 
> "address": {
> 
> "countryCode": "AU",
> 
> "state": "VIC",
> 
> "city": "Melbourne",
> 
> "postcode": "",
> 
> "street": "FCC",
> 
> "street2": "",
> 
> "detail": ""
> 
> },
> 
> "properties": {
> 
> "K1X3X15": "20121109",
> 
> "K2X1X1": "10.10.10.11",
> 
> "K1X3X14": "",
> 
> "K1X3X13": "",
> 
> "K2X1X2": "",
> 
> "K1X3X12": "02 8972 5897",
> 
> "K2X1X3": "FCC",
> 
> "K2X1X4": "10.0",
> 
> "K2X1X5": "",
> 
> "K1X3X16": "1 Year",
> 
> "K1X3X8": "",
> 
> "K1X1X1": "FCC",
> 
> "K1X2X5": "",
> 
> "K1X2X4": "FCC",
> 
> "K1X1X2": "PLD-DRG-A-6112",
> 
> "K1X3X7": "Dell PowerEdge R710",
> 
> "K1X1X3": "",
> 
> "K1X3X9": "Current",
> 
> "K1X2X1": "Server",
> 
> "K1X3X11": "Zac Cochrane",
> 
> "K1X3X10": "DELL Aust Pty Ltd",
> 
> "K1X2X3": "FCC",
> 
> "K1X2X2": "FCC",
> 
> "K3X1X4": "",
> 
> "K3X1X3": "",
> 
> "K3X1X2": "",
> 
> "K3X1X1": "",
> 
> "K1X3X5": "Physical Key: 
> 
> ```
> 
> YTF2W-KFJ3P-3W447-8K3J4-42VVQ\nVirtual Key: 39C2W-H7QWQ-DBH43-37MJ8-HPD2G",
> 
> ```
> "K1X3X6": "",
> 
> "K1X3X3": "IM0004-D-0003 Hardware Architectural 
> 
> ```
> 
> Design Document \nIM0004-D-0004 Peninsula link Device List",
> 
> ```
> "K1X3X4": "IM0004-PLG-SP-I-0036 Dell PowerEdge 
> 
> ```
> 
> R710",
> 
> ```
> "K1X3X1": "20111109",
> 
> "K1X3X2": "Meridian Cluster Node2"
> 
> },
> 
> "productId": 4,
> 
> "assetCategoryId": 0
> 
> }
> 
> }
> 
> ]
> 
> }
> 
> ```
> 
> As you can see my location field has two sub fields latitude/longitude  
> (under \_source).
> 
> I would like to retrieve all documents with the distance 500m from  
> location [1, 1] using Java.
> 
> I am trying to play with this code:
> 
> SearchRequestBuilder srb =  
> client.prepareSearch("asset\_index").setTypes("Asset").setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());
> 
> srb.setFilter(FilterBuilders.geoDistanceRangeFilter("filter1").lat(1).lon(1).geoDistance(  
> GeoDistance.PLANE));
> 
> How can I specify the distance 500 m from lat/long[1/1]?
> 
> Any suggestions?
> 
> Regards,
> 
> Janusz

--

---

<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 15, 2013, 5:38am UTC](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287/18 "2013-01-15T05:38:26Z")

</div>

Yes. That's it but you have to create your index before sending a mapping for this index.  
Look: [https://github.com/elasticsearchfr/elasticsearch-java-tests/blob/master/src/test/java/org/elasticsearchfr/tests/ES003PutMappingNotAnalyzedTest.java#L28](https://github.com/elasticsearchfr/elasticsearch-java-tests/blob/master/src/test/java/org/elasticsearchfr/tests/ES003PutMappingNotAnalyzedTest.java#L28)

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

Le 15 janv. 2013 à 02:53, JD [jdalecki@tycoint.com](mailto:jdalecki@tycoint.com) a écrit :

Hi David,  
I think I am still missing something.  
When I try to create mapping before I create river for the collection Asset I get this exception:  
org.elasticsearch.indices.IndexMissingException: [asset\_index] missing  
at org.elasticsearch.cluster.metadata.MetaData.convertFromWildcards(MetaData.java:602)  
at org.elasticsearch.cluster.metadata.MetaData.concreteIndices(MetaData.java:514)  
at org.elasticsearch.cluster.metadata.MetaData.concreteIndices(MetaData.java:497)  
at org.elasticsearch.action.admin.indices.mapping.put.TransportPutMappingAction.doExecute(TransportPutMappingAction.java:74)  
at org.elasticsearch.action.admin.indices.mapping.put.TransportPutMappingAction.doExecute(TransportPutMappingAction.java:41)  
at org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:61)  
at org.elasticsearch.client.node.NodeIndicesAdminClient.execute(NodeIndicesAdminClient.java:72)  
at org.elasticsearch.client.support.AbstractIndicesAdminClient.putMapping(AbstractIndicesAdminClient.java:290)  
at org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder.doExecute(PutMappingRequestBuilder.java:109)  
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:62)  
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:57)  
at com.tycoint.eams.servlet.UploadXml.buildAssetMapping(UploadXml.java:147)  
at com.tycoint.eams.servlet.UploadXml.doPost(UploadXml.java:46)  
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)  
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)  
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)  
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)  
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)  
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)  
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)  
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)  
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)  
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)  
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)  
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)  
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)  
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)  
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)  
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
at java.lang.Thread.run(Thread.java:662)

When you say "send mapping before creating river" you mean to execute this code - is that right?:  
PutMappingResponse response = node.client().admin().indices()  
.preparePutMapping("asset\_index")  
.setType("Asset")  
.setSource(xbMapping)  
.execute().actionGet();  
Regards,  
Janusz

On Thursday, January 10, 2013 1:53:00 PM UTC+11, JD wrote:

> Hi,  
> I have a quite a few documents like this that are indexed in elasticsearch db (attached is just one for an example):  
> {  
> "took": 28,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 5,  
> "successful": 5,  
> "failed": 0  
> },  
> "hits": {  
> "total": 694,  
> "max\_score": 1,  
> "hits": [  
> {  
> "\_index": "asset\_index",  
> "\_type": "Asset",  
> "\_id": "4",  
> "\_score": 1,  
> "\_source": {  
> "\_id": 4,  
> "className": "com.tycoint.eams.mongodb.AssetDB",  
> "name": "FCC\_SRV02",  
> "serialNo": "Service Tag: 5S2HB2S\nExpress Service Tag: 12581131348",  
> "description": "Meridian Server Node 2 (Dell PowerEdge R710)",  
> "location": {  
> "latitude": 5,  
> "longitude": 5  
> },  
> "address": {  
> "countryCode": "AU",  
> "state": "VIC",  
> "city": "Melbourne",  
> "postcode": "",  
> "street": "FCC",  
> "street2": "",  
> "detail": ""  
> },  
> "properties": {  
> "K1X3X15": "20121109",  
> "K2X1X1": "10.10.10.11",  
> "K1X3X14": "",  
> "K1X3X13": "",  
> "K2X1X2": "",  
> "K1X3X12": "02 8972 5897",  
> "K2X1X3": "FCC",  
> "K2X1X4": "10.0",  
> "K2X1X5": "",  
> "K1X3X16": "1 Year",  
> "K1X3X8": "",  
> "K1X1X1": "FCC",  
> "K1X2X5": "",  
> "K1X2X4": "FCC",  
> "K1X1X2": "PLD-DRG-A-6112",  
> "K1X3X7": "Dell PowerEdge R710",  
> "K1X1X3": "",  
> "K1X3X9": "Current",  
> "K1X2X1": "Server",  
> "K1X3X11": "Zac Cochrane",  
> "K1X3X10": "DELL Aust Pty Ltd",  
> "K1X2X3": "FCC",  
> "K1X2X2": "FCC",  
> "K3X1X4": "",  
> "K3X1X3": "",  
> "K3X1X2": "",  
> "K3X1X1": "",  
> "K1X3X5": "Physical Key: YTF2W-KFJ3P-3W447-8K3J4-42VVQ\nVirtual Key: 39C2W-H7QWQ-DBH43-37MJ8-HPD2G",  
> "K1X3X6": "",  
> "K1X3X3": "IM0004-D-0003 Hardware Architectural Design Document \nIM0004-D-0004 Peninsula link Device List",  
> "K1X3X4": "IM0004-PLG-SP-I-0036 Dell PowerEdge R710",  
> "K1X3X1": "20111109",  
> "K1X3X2": "Meridian Cluster Node2"  
> },  
> "productId": 4,  
> "assetCategoryId": 0  
> }  
> }  
> ]  
> }
> 
> As you can see my location field has two sub fields latitude/longitude (under \_source).  
> I would like to retrieve all documents with the distance 500m from location [1, 1] using Java.  
> I am trying to play with this code:  
> SearchRequestBuilder srb = client.prepareSearch("asset\_index").setTypes("Asset").setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());  
> srb.setFilter(FilterBuilders.geoDistanceRangeFilter("filter1").lat(1).lon(1).geoDistance(GeoDistance.PLANE));  
> How can I specify the distance 500 m from lat/long[1/1]?  
> Any suggestions?  
> Regards,  
> Janusz

--

--

---

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [January 15, 2013, 8:56am UTC](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287/19 "2013-01-15T08:56:13Z")

</div>

When I execute this code:

_node_ = NodeBuilder._nodeBuilder_().node();

_node_.client().admin().indices().prepareCreate("asset\_index"  
).execute().actionGet();

I am getting this exception:\*\*

_org.elasticsearch.indices.IndexAlreadyExistsException_: [asset\_index]  
Already exists

```
            at 

```

org.elasticsearch.cluster.metadata.MetaDataCreateIndexService.validate(\*  
MetaDataCreateIndexService.java:476\*)

```
            at 

```

org.elasticsearch.cluster.metadata.MetaDataCreateIndexService.access$100(\*  
MetaDataCreateIndexService.java:79\*)

```
            at 

```

org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$1.execute(\*  
MetaDataCreateIndexService.java:139\*)

```
            at 

```

org.elasticsearch.cluster.service.InternalClusterService$2.run(\*  
InternalClusterService.java:223\*)

```
            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(*

```

ThreadPoolExecutor.java:886\*)

```
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(*

```

ThreadPoolExecutor.java:908\*)

```
            at java.lang.Thread.run(*Thread.java:662*)

```

However I know the index does not exist as I checked it using both plugin  
head gui and by executing this request:  
[http://localhost:9200/asset\_index/\_search](http://localhost:9200/asset_index/_search) (getting {

```
"error": "IndexMissingException[[asset_index] missing]",

"status": 404

```

})\*\*

I am still missing something,

Regards,

Janusz

On Thursday, January 10, 2013 1:53:00 PM UTC+11, JD wrote:

> Hi,
> 
> I have a quite a few documents like this that are indexed in elasticsearch  
> db (attached is just one for an example):
> 
> {
> 
> ```
> "took": 28,
> 
> "timed_out": false,
> 
> "_shards": {
> 
> "total": 5,
> 
> "successful": 5,
> 
> "failed": 0
> 
> },
> 
> "hits": {
> 
> "total": 694,
> 
> "max_score": 1,
> 
> "hits": [
> 
> {
> 
> "_index": "asset_index",
> 
> "_type": "Asset",
> 
> "_id": "4",
> 
> "_score": 1,
> 
> "_source": {
> 
> "_id": 4,
> 
> "className": "com.tycoint.eams.mongodb.AssetDB",
> 
> "name": "FCC_SRV02",
> 
> "serialNo": "Service Tag: 5S2HB2S\nExpress Service 
> 
> ```
> 
> Tag: 12581131348",
> 
> ```
> "description": "Meridian Server Node 2 (Dell PowerEdge 
> 
> ```
> 
> R710)",
> 
> ```
> "location": {
> 
> "latitude": 5,
> 
> "longitude": 5
> 
> },
> 
> "address": {
> 
> "countryCode": "AU",
> 
> "state": "VIC",
> 
> "city": "Melbourne",
> 
> "postcode": "",
> 
> "street": "FCC",
> 
> "street2": "",
> 
> "detail": ""
> 
> },
> 
> "properties": {
> 
> "K1X3X15": "20121109",
> 
> "K2X1X1": "10.10.10.11",
> 
> "K1X3X14": "",
> 
> "K1X3X13": "",
> 
> "K2X1X2": "",
> 
> "K1X3X12": "02 8972 5897",
> 
> "K2X1X3": "FCC",
> 
> "K2X1X4": "10.0",
> 
> "K2X1X5": "",
> 
> "K1X3X16": "1 Year",
> 
> "K1X3X8": "",
> 
> "K1X1X1": "FCC",
> 
> "K1X2X5": "",
> 
> "K1X2X4": "FCC",
> 
> "K1X1X2": "PLD-DRG-A-6112",
> 
> "K1X3X7": "Dell PowerEdge R710",
> 
> "K1X1X3": "",
> 
> "K1X3X9": "Current",
> 
> "K1X2X1": "Server",
> 
> "K1X3X11": "Zac Cochrane",
> 
> "K1X3X10": "DELL Aust Pty Ltd",
> 
> "K1X2X3": "FCC",
> 
> "K1X2X2": "FCC",
> 
> "K3X1X4": "",
> 
> "K3X1X3": "",
> 
> "K3X1X2": "",
> 
> "K3X1X1": "",
> 
> "K1X3X5": "Physical Key: 
> 
> ```
> 
> YTF2W-KFJ3P-3W447-8K3J4-42VVQ\nVirtual Key: 39C2W-H7QWQ-DBH43-37MJ8-HPD2G",
> 
> ```
> "K1X3X6": "",
> 
> "K1X3X3": "IM0004-D-0003 Hardware Architectural 
> 
> ```
> 
> Design Document \nIM0004-D-0004 Peninsula link Device List",
> 
> ```
> "K1X3X4": "IM0004-PLG-SP-I-0036 Dell PowerEdge 
> 
> ```
> 
> R710",
> 
> ```
> "K1X3X1": "20111109",
> 
> "K1X3X2": "Meridian Cluster Node2"
> 
> },
> 
> "productId": 4,
> 
> "assetCategoryId": 0
> 
> }
> 
> }
> 
> ]
> 
> }
> 
> ```
> 
> As you can see my location field has two sub fields latitude/longitude  
> (under \_source).
> 
> I would like to retrieve all documents with the distance 500m from  
> location [1, 1] using Java.
> 
> I am trying to play with this code:
> 
> SearchRequestBuilder srb =  
> client.prepareSearch("asset\_index").setTypes("Asset").setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());
> 
> srb.setFilter(FilterBuilders.geoDistanceRangeFilter("filter1").lat(1).lon(1).geoDistance(  
> GeoDistance.PLANE));
> 
> How can I specify the distance 500 m from lat/long[1/1]?
> 
> Any suggestions?
> 
> Regards,
> 
> Janusz

--

---

<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 15, 2013, 9:18am UTC](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287/20 "2013-01-15T09:18:30Z")

</div>

That probably means that your node in Java is not a client Node but is holding  
also documents.  
Add nodeBuilder().client(true).node() (as far as I remember it) when you build  
your client node.  
Remove also your local data dir before relaunching the test. Some documents are  
remaining in your local data dir.

Also, If you want to make sure by code, you can first delete your index and  
catch properly the IndexMissingException and then create it.

Does it help?

Le 15 janvier 2013 à 09:56, JD [jdalecki@tycoint.com](mailto:jdalecki@tycoint.com) a écrit :

> When I execute this code:  
> node = NodeBuilder.nodeBuilder().node();
> 
> ```
> node.client().admin().indices().prepareCreate("asset_index").execute().actionGet();
> 
> ```
> 
> I am getting this exception:
> 
> org.elasticsearch.indices.IndexAlreadyExistsException: [asset\_index] Already  
> exists
> 
> ```
> at
> 
> ```
> 
> org.elasticsearch.cluster.metadata.MetaDataCreateIndexService.validate(MetaDataCreateIndexService.java:476)
> 
> ```
> at
> 
> ```
> 
> org.elasticsearch.cluster.metadata.MetaDataCreateIndexService.access$100(MetaDataCreateIndexService.java:79)
> 
> ```
> at
> 
> ```
> 
> org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$1.execute(MetaDataCreateIndexService.java:139)
> 
> ```
> at
> 
> ```
> 
> org.elasticsearch.cluster.service.InternalClusterService$2.run(InternalClusterService.java:223)
> 
> ```
> at
> 
> ```
> 
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
> 
> ```
> at
> 
> ```
> 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
> 
> ```
> at java.lang.Thread.run(Thread.java:662)
> 
> ```
> 
> However I know the index does not exist as I checked it using both plugin  
> head gui and by executing this request:  
> [http://localhost:9200/asset\_index/\_search](http://localhost:9200/asset_index/_search)  
> [http://localhost:9200/asset\_index/\_search](http://localhost:9200/asset_index/_search) (getting {
> 
> ```
> "error": "IndexMissingException[[asset_index] missing]",
> 
> "status": 404
> 
> ```
> 
> })
> 
> I am still missing something,
> 
> Regards,
> 
> Janusz
> 
> On Thursday, January 10, 2013 1:53:00 PM UTC+11, JD wrote:
> 
> > > 
> > 
> > Hi,
> > 
> > I have a quite a few documents like this that are indexed in  
> > elasticsearch db (attached is just one for an example):
> > 
> > {
> > 
> > ```
> > "took": 28,
> > 
> > "timed_out": false,
> > 
> > "_shards": {
> > 
> > "total": 5,
> > 
> > "successful": 5,
> > 
> > "failed": 0
> > 
> > },
> > 
> > "hits": {
> > 
> > "total": 694,
> > 
> > "max_score": 1,
> > 
> > "hits": [
> > 
> > {
> > 
> > "_index": "asset_index",
> > 
> > "_type": "Asset",
> > 
> > "_id": "4",
> > 
> > "_score": 1,
> > 
> > "_source": {
> > 
> > "_id": 4,
> > 
> > "className": "com.tycoint.eams.mongodb.AssetDB",
> > 
> > "name": "FCC_SRV02",
> > 
> > "serialNo": "Service Tag: 5S2HB2S\nExpress Service
> > 
> > ```
> > 
> > Tag: 12581131348",
> > 
> > ```
> > "description": "Meridian Server Node 2 (Dell
> > 
> > ```
> > 
> > PowerEdge R710)",
> > 
> > ```
> > "location": {
> > 
> > "latitude": 5,
> > 
> > "longitude": 5
> > 
> > },
> > 
> > "address": {
> > 
> > "countryCode": "AU",
> > 
> > "state": "VIC",
> > 
> > "city": "Melbourne",
> > 
> > "postcode": "",
> > 
> > "street": "FCC",
> > 
> > "street2": "",
> > 
> > "detail": ""
> > 
> > },
> > 
> > "properties": {
> > 
> > "K1X3X15": "20121109",
> > 
> > "K2X1X1": "10.10.10.11",
> > 
> > "K1X3X14": "",
> > 
> > "K1X3X13": "",
> > 
> > "K2X1X2": "",
> > 
> > "K1X3X12": "02 8972 5897",
> > 
> > "K2X1X3": "FCC",
> > 
> > "K2X1X4": "10.0",
> > 
> > "K2X1X5": "",
> > 
> > "K1X3X16": "1 Year",
> > 
> > "K1X3X8": "",
> > 
> > "K1X1X1": "FCC",
> > 
> > "K1X2X5": "",
> > 
> > "K1X2X4": "FCC",
> > 
> > "K1X1X2": "PLD-DRG-A-6112",
> > 
> > "K1X3X7": "Dell PowerEdge R710",
> > 
> > "K1X1X3": "",
> > 
> > "K1X3X9": "Current",
> > 
> > "K1X2X1": "Server",
> > 
> > "K1X3X11": "Zac Cochrane",
> > 
> > "K1X3X10": "DELL Aust Pty Ltd",
> > 
> > "K1X2X3": "FCC",
> > 
> > "K1X2X2": "FCC",
> > 
> > "K3X1X4": "",
> > 
> > "K3X1X3": "",
> > 
> > "K3X1X2": "",
> > 
> > "K3X1X1": "",
> > 
> > "K1X3X5": "Physical Key:
> > 
> > ```
> > 
> > YTF2W-KFJ3P-3W447-8K3J4-42VVQ\nVirtual Key: 39C2W-H7QWQ-DBH43-37MJ8-HPD2G",
> > 
> > ```
> > "K1X3X6": "",
> > 
> > "K1X3X3": "IM0004-D-0003 Hardware Architectural
> > 
> > ```
> > 
> > Design Document \nIM0004-D-0004 Peninsula link Device List",
> > 
> > ```
> > "K1X3X4": "IM0004-PLG-SP-I-0036 Dell PowerEdge
> > 
> > ```
> > 
> > R710",
> > 
> > ```
> > "K1X3X1": "20111109",
> > 
> > "K1X3X2": "Meridian Cluster Node2"
> > 
> > },
> > 
> > "productId": 4,
> > 
> > "assetCategoryId": 0
> > 
> > }
> > 
> > }
> > 
> > ]
> > 
> > }
> > 
> > ```
> > 
> > As you can see my location field has two sub fields latitude/longitude  
> > (under \_source).
> > 
> > I would like to retrieve all documents with the distance 500m from  
> > location [1, 1] using Java.
> > 
> > I am trying to play with this code:  
> > SearchRequestBuilder srb =  
> > client.prepareSearch("asset\_index").setTypes("Asset").setSearchType(SearchType.DEFAULT).setQuery(QueryBuilders.matchAllQuery());
> > 
> > ```
> > srb.setFilter(FilterBuilders.geoDistanceRangeFilter("filter1").lat(1).lon(1).geoDistance(GeoDistance.PLANE));
> > 
> > ```
> > 
> > How can I specify the distance 500 m from lat/long[1/1]?
> > 
> > Any suggestions?
> > 
> > Regards,
> > 
> > Janusz
> > 
> > --
> > 
> > >

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

[Next page](https://discuss.elastic.co/t/java-search-for-lat-long-fields/10287.md?page=2)
