I have a problem with the search for GeoDistance in Elasticsearch.
I have in my documents the latitude and longitude of the users according to the Zip code.
With that, I had to include in my system the autocomplete of google addresses to be able to search for a user closer to the given address and I added a radius bar, where I need to inform that I want users close to that address in up to X KM of distance.
The problem is, if I search for a more precise address, with street name, elastic normally finds the user.
But if I enter a more general address, such as a city or country, the search returns nothing.
I believe it has something to do with the search radius, but I haven't found a solution for that.
Here is my code:
if (filters.Latitude! = null && filters.Longitude! = null)
{
//filtros.RangeLogradouro = 20 Km
andQuery & = queryBuilder.GeoDistance (b => b
.Distance (Distance.Kilometers (filters.RangeLogradouro))
.Field (p => p.Location)
.Boost (1.1)
.ValidationMethod (GeoValidationMethod.IgnoreMalformed)
.Location (new GeoLocation (latitude: filters.Latitude, longitude: filters.Longitude))
);
}
Has anyone experienced this problem and managed to solve it?
Thank you.
Related
I'm struggling with writing this query
I want to find all of the workers,
who have friends of 1st degree, 2nd degree AND 3rd degree,
who follows 2 conditions.
but if one of the above connections does not apply to the conditions,
I do not want it to be in the output
for example:
the relationship is friend.
conditions are:
City: "New Delhi"
age >= 29
friend , friend of friend , friend of friend of friend - Direction irrelevant
if the node has a friend that not apply to the conditions even though it has another path that does apply I do not want it
Graph DB
MATCH (u1)-[:friend]-(u2)-[:friend]-(u3)-[:friend]-(u4)
WHERE(u1.address = "New Delhi" AND u1.age >= 29)
AND (u2.address = "New Delhi" AND u2.age >= 29)
AND (u3.address = "New Delhi" AND u3.age >= 29)
AND (u4.address = "New Delhi" AND u4.age >= 29)
RETURN DISTINCT u3.name
This query gives me all the nodes that I wanted and more..
it does not filter the ones that have a relationship with someone that not apply the conditions
I will be more clear:
a-b-c-d path that apply the conditions MARK it P
a-q-w-v q OR w OR v do not apply the conditions MARK it N
because of P a will be in the output but because of N it should not be
Who stand the requirements and Output
I added this picture for graphic explanation
the mark with black circle is the output-> every one in chain apply the conditions
Green is apply the conditions
Red is not.
Hillel, Tor and Dror. They apply the conditions but the have friends or friend of friends or friend of friends of friends that does not. So they will not be in the output.
The out put for my Query is the black circles and the 3 names above how to I do it with out those 3.
sorry for all the extra details I tried in neo4j manual to find an answer but with no luck
I am trying to create a pie chart in Kibana (V2.3.1) which displays values from multiple fields.
Lets say I got documents representing humans with the following fields: (representing if the finger is bent or straight)
Human 1:
human.right_arm.thumb = bent
human.right_arm.pinky = straight
human.left_arm.thumb = straight
human.left_arm.pinky = half-bent
Human 2:
human.right_arm.thumb = straight
human.right_arm.pinky = bent
human.left_arm.thumb = half-bent
human.left_arm.pinky = half-bent
Now I want to create a pie chart on the status of all the fingers. It would create a result like:
bent (= 2) = 25% coverage of the pie
straight (= 3) = 37.5% coverage of the pie
half-bent (= 3) = 37.5% coverage of the pie
In Kibana I can only split one field per chart. So how do I combine the results for all fingers?
And how can I get the same status but then from all the thumbs?
I think scripted fields are the way to go, but I cannot figure out how since as far as I can see the aggregation only combines the results of fields while it should represent a set of fields ("all fingers" or "all thumbs").
I searched the web and found similar issues but never a clear answer.
If necessary I can make changes in Logstash. We use the ruby/code filter to define these fields.
Note: Sadly I am not able to update our ELK stack to a newer version.
Can you make the state of the finger an separate aggregatable field? Then you'll be able to create a pie chart with a count metric and split the slices by terms and then choose the field with the name of the state of the finger.
Eg.
Otherwise, this scripted field might work (not tested since I don't have the necessary setup):
def fingerState = doc['whatever the field is called'].value;
if (fingerState != null)
{
int index = fingerState.lastIndexOf('=');
if (index > 0)
{
return fingerState.substring(index+1);
}
}
return fingerState; //this will return the whole thing if for some reason this format isnt consistent
As for the second question, you can do something like
but for this to work you need to make the state of finger aggregatable.
Hope this works and that it's compatible with your version on ELK (I'm using 5.2)
I am working on a current scenario where there is a need to boost few documents in case if there is a particular text search.
The scenario is, I have a set of documents where I have to do the term query based on a particular keyword , but the catch here is. Let's say we search for a keyword test it will fetch 100 records but the requirement says that few docs should always come as top result, irrespective of there weightage and other criteria. How can we achieve this is Elasticsearch, any suggestion and ideas are most welcome.
You can control relevance with scripts. Take a look at:
https://www.elastic.co/guide/en/elasticsearch/guide/current/script-score.html
This is an example using Groovy:
price = doc['price'].value
margin = doc['margin'].value
if (price < threshold) {
return price * margin / target
}
return price * (1 - discount) * margin / target
So, in pseudo-code it would be something like:
if (word == 'test') {
return score * n
}
return score
i am a beginner & developing my very first project with lucene.net i.e. an address search utility, lucene.net 3.0.3
using standard analyzer, query parser, (suppose i have a single field, Stored & Analyzed as well)
- sample data : (every row is a document with a single field)
(Postcode and street column concatenated)
UB6 9AH Greenford Road something
UB6 9AP Greenford Road something
UB1 3EB Greenford Road something
PR8 3JT Greenford Road something
HA1 3QD something Greenford Road
SM1 1JY something Greenford Road something
Searching
StringBuilder customQuery = new StringBuilder();
customQuery.Append(_searchFieldName + ":\"" + searchTerm + "\"^" + (wordsCount));
// this is for phrase matching
foreach (var word in words.Where(word => !string.IsNullOrEmpty(word)))
{
customQuery.Append(" +" + _searchFieldName + ":" + word + "*");
}
// this is prefix match for each word
Query query = _parser.Parse(customQuery.ToString());
_searcher.Search(query, collector);
all above (searching) working fine
Question
if i search for "Greenford road" ,
i may want that row that has 'SM1' should come up (means i want to priorities result as per postcode)
i have tested Query-Time-Boost and it works fine
but i may have a long list of priority postcodes sometimes (so i don't want to loop over each postcode and set its priority at query time
I WANT DOCUMENT TIME BOOSTING
but whatever document boost i set (at the time of indexing), it doesn't effect my search results
doc.Add(new Field(SearchFieldName, SearchField, Field.Store.YES, Field.Index.ANALYZED));
if (condition == true)
{
doc.Boost = 2; // or 5 or 200 etc (nothing works)
}
please HELP
i tried to understand similarity and scoring, but its too much mathematics there...
please help....
I recently had this problem myself and I think it might be due to wildcard queries (It was in my case at least). There is another post here that explains the issue better, and provides a possible solution:
Lucene .net Boost not working when using * wildcard
I am quite new to Linq to Entity and having some trouble.
Here's my Search repository:
public static List<Centre> Search(Search search)
{
using (var context = new MeetingRoomsContext())
{
var query = context.Centres
.Include("Geo")
.OrderBy( NEED HELP WITH THIS PART )
return query.ToList();
}
}
I am getting a search object which contains co-ordinates like this:
Search.LongLat = "(-6.265275, 53.334442)"
I need to break that out and do some maths against the co-ordinates in the DB in order to order results by the closest to the searched point for first.
In mathematical terms it would be pythagoras:
squareRootOf((difference in latitude * difference in latitude) +
(difference in longitude * difference in longitude))
Really haven't a clue how to do this. Any help appreciated greatly
There is no need for a square root at all; ordering by the square of the distance is the same as ordering by the distance:
.OrderBy(x => (x.Latitude - target.Latitude)*(x.Latitude - target.Latitude)
+ (x.Longitude - target.Longitude)*(x.Longitude - target.Longitude))
This trick is often used in collision detection (such as for video games) to avoid having to calculate many square roots.
How about implementing your own IComparer that calculates that pythagorean square root? Then the OrderBy will automatically compare off that.
See this post for an example.