I have such information for saving to ES in my json:
{
"geolocation": {
"latitude": 50.443278299999996,
"longitude": 30.5075698,
"accuracy": 3966
}
}
geolocation in my Java object is GeoPoint (private GeoPoint geolocation). How I can pass an accuracy to GeoPoint? Or maybe there is another type for saving location with lat, lon and accuracy?
P.S. For parsing I use:
public GenericResponse<?> addUserInfo(#RequestBody UserInformation userInformation) {
}
And geolocation is one of the fields in UserInformation class.
I believe you are missing something. Accuracy or distance, it's something that you specify when querying, not when saving something. For example:
You have one entry in your elasticsearch. This entry has a geo_point field that includes lat and lon.
When you search for this profile you have a geo point, which represents a location and you want, based on this location (let's name it query location) to find all entries in elasticsearch that have a distance of X meters from you.
Basically there is no distance/accuracy to save. Given a geo query, elasticsearch will calculate the distance between these two points and it will check if it is smaller than the distance/accuracy you provided (during query), if it is, it will include the entry.
Related
Below is my SQL query
select public.st_within(
public.ST_SetSRID(
public.ST_MakePoint(12.9135218,77.5950804),
4326
),
(public.ST_SetSRID((select boundary
from location
where id =3209901),4326)
)
);
I'm trying to fetch records which are falling under Bangalore location (12.9135218,77.5950804).
In my table I have a geometry object with Bangalore location.
But still it is returning false.
I'm using PostgreSQL.
Longitude 12.9135218 and latitude 77.5950804 mark a point near Spitzbergen, quite far from Bangalore.
Either bring warm clothing, or use the coordinates (77.5950804,12.9135218).
I use this tutorial : Using OpenWeatherMap API Key
When I use this url with the city name the name is correct. So if I put "Paris" I have the word "Paris" on my application:
URL url = new URL("http://api.openweathermap.org/data/2.5/weather?q="+city+"&APPID=ea574594b9d36ab688642d5fbeab847e");
But when I try to do the same thing with latitude and longitude instead of the name of the city. The data of temperature, wind, pressure, ... are right. There is just the name of the city that is not right. Instead of having "Paris" I have something else.
URL url = new URL("http://api.openweathermap.org/data/2.5/weather?lat=%s&lon=%s&APPID=ea574594b9d36ab688642d5fbeab847e");
Example, by entering this into the browser. The numbers are reduced to two digits after the decimal point.
Suppose I have 10 instances of an object that has some fields. One of the field specify the ID. Two other fields have data regarding the location (latitude and longitude). One field has date time information.
In these 10 instances say the ID remains the same but fields related to date time and location changes.
Instance1 = id - 123; lat - 58.00; lon - 16.00; date - 2017-07-11 12:19:00
Instance1 = id - 123; lat - 60.00; lon - 17.00; date - 2017-07-11 12:29:00
Instance1 = id - 123; lat - 62.00; lon - 18.00; date - 2017-07-11 12:39:00
Instance1 = id - 123; lat - 64.00; lon - 19.00; date - 2017-07-11 12:49:00
Instance1 = id - 123; lat - 66.00; lon - 20.00; date - 2017-07-11 12:59:00
The above data is dummy data. But you can observe that id remains the same, just position and time changes.
Using java, spring-data-elasticsearch i am able to put the information in elastic search.
The problem that i face is that in elastic search the total number of documents that are created is 1.
First a document with id as 123 is created and then that document is updated 9 times. So the final document has _version as 10.
How can i create 10 different documents in elastic search with same id.
Another thing to note is that these fields are not present in same class, the actual data object is quite complex, but as a whole the data object will have these fields. Also the data object can have different type of instances but these fields will be present.
If these fields would have been present in a same class then i could have used the fields for generating hashcode, so that a unique has code is generated and thus be used for ID.
Please can someone suggest how can i achieve in creating different documents...or a single document but having 10 sub instances in elastic search.
Thanks
from documentation
_id field Each document has an _id that uniquely identifies it, which is indexed so that documents can be looked up either with the GET API
or the ids query.
Spring will map id in class to _id in elasticsearch document.
_id in elasticsearch plays very specific role and can not accommodate discribed functionality.
I would suggest you to use different field name like InstanceId. In this case it will be possible to have same value in different documents.
Hi was going to use Geofire for this but as its not compatiable with the latest version of Firebase yet I will hold off using it for now.
I have a simple database entry that looks like this...
author: "Aidan Mack"
lat: 58.9551641
long: -1.1091357
title: "hello"
userID: "userid"
I want to send a lat/long and distance radius and get back db entrys like the above within the given radius... any ideas how I would go about it with out using geofire?
Thanks
Aidan
Given JSON in ES index in the following format:
{
"pin": {
"id": 123,
"location": {
"lat": 456,
"lon":-789
}
}
}
The following gets the document matching the id field:
client.prepareSearch("index_name")
.setTypes("pin")
.setQuery(QueryBuilders.termQuery("id", 123))
.execute()
.actionGet();
Instead, I 'm trying to match multiple fields, ie. (location.lat, location.lon).
QueryBuilders.termQuery(); // accepts only a single term
Tried few alternatives but none of it seems to work, eg:
QueryBuilder queryBuilder = QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery("location.lat", 456))
.must(QueryBuilders.termQuery("location.lon", -789));
client.prepareSearch("index_name")
.setTypes("pin")
.setQuery(queryBuilder)
.execute()
.actionGet();
By default, a geo_point field is not indexed as two fields (location.lat and location.lon), it's indexed as a single field that contains both latitude and longitude.
You can turn on indexing of latitude and longitude by turning on the lat_lon mapping option. However, in your example, the values for latitude and longitude are too large. So, they are normalized, converted to double and indexed as -84.0 and -69.0 instead of 456 and -789. So, if you will enable lat_lon and replace the value in the queries, you should be able to get the results.
Please note that values for latitude and longitude are converted to double before indexing. So using term queries might not be very practical in the long term since you will have to always take rounding errors into consideration. It might be more useful to use range queries or elasticsearch geospatial queries instead.
Check out the bool query in ElasticSearch, you should be able to specify must, should or should_not to get the appropriate mixture of and/or for your query.
QueryBuilder qb = boolQuery()
.must(termsQuery("content", Arrays.asList("test1", "test4")));
https://www.elastic.co/guide/en/elasticsearch/guide/current/_finding_multiple_exact_values.html
You can use QueryBuilders.multiMatchQuery instead of QueryBuilders.termQuery