Java search for lat/long fields

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
21 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Java search for lat/long fields

Janusz Dalecki

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

 

 

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Java search for lat/long fields

dadoonet
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 <[hidden email]> 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://dev.david.pilato.fr/
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Java search for lat/long fields

Janusz Dalecki
In reply to this post by Janusz Dalecki

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” 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

 

 

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Java search for lat/long fields

Janusz Dalecki
In reply to this post by Janusz Dalecki
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

 

 

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Java search for lat/long fields

dadoonet
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
 
David

Le 11 janvier 2013 à 03:29, JD <[hidden email]> 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://dev.david.pilato.fr/
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Java search for lat/long fields

Janusz Dalecki
In reply to this post by Janusz Dalecki

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

 

 

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Java search for lat/long fields

Janusz Dalecki
In reply to this post by Janusz Dalecki

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) 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

 

 

--
 
 

my_mapping.txt (5K) Download Attachment
one_asset.txt (2K) Download Attachment
mappin_code.java (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Java search for lat/long fields

dadoonet
In reply to this post by Janusz Dalecki
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 <[hidden email]> 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

 

 

--
 
 

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Java search for lat/long fields

Janusz Dalecki
In reply to this post by Janusz Dalecki
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

 

 

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Java search for lat/long fields

dadoonet
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 <[hidden email]> 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

 

 

--
 
 

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Java search for lat/long fields

Janusz Dalecki
In reply to this post by Janusz Dalecki
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

 

 

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Java search for lat/long fields

dadoonet
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 <[hidden email]> 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

 

 

--
 
 

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Java search for lat/long fields

dadoonet
Ok. I double checked and scripts are already there in mongo river. Just read the 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 <[hidden email]> 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 < [hidden email]> 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://dev.david.pilato.fr/
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Java search for lat/long fields

Janusz Dalecki
In reply to this post by Janusz Dalecki
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

 

 

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Java search for lat/long fields

Janusz Dalecki
In reply to this post by Janusz Dalecki
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

 

 

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Java search for lat/long fields

dadoonet
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 <[hidden email]> 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

 

 

--
 
 

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Java search for lat/long fields

Janusz Dalecki
In reply to this post by Janusz Dalecki
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

 

 

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Java search for lat/long fields

dadoonet

--
David ;-)
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs


Le 15 janv. 2013 à 02:53, JD <[hidden email]> 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

 

 

--
 
 

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Java search for lat/long fields

Janusz Dalecki
In reply to this post by Janusz Dalecki

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 (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

 

 

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Java search for lat/long fields

dadoonet
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 <[hidden email]> 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 (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://dev.david.pilato.fr/
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--
 
 
12