blevesearch / bleve

A modern text/numeric/geo-spatial/vector indexing library for go
Apache License 2.0
10.04k stars 680 forks source link

Struggling with making `NewGeoDistanceQuery` work #2080

Open CGenie opened 2 weeks ago

CGenie commented 2 weeks ago

Hello,

I have this simple code: https://git.sr.ht/~cgenie/bleve-geo-test/tree/master/item/main.go

I basically copied it from issue https://github.com/blevesearch/bleve/issues/1789 and applied the fixes about indexMapping.TypeField = "type". However, the results are still empty for me:

go run .
ERR:  <nil>
searchResult1 ->  No matches
ERR:  <nil>
searchResult2 ->  2 matches, took 58.666µs

What am I doing wrong?

CGenie commented 2 weeks ago

BTW, if my doc has field name Location and the json transforms that to lowercase location should I put field name in index capitalized or lowercase?

metonymic-smokey commented 1 week ago

Hi @CGenie apologies for the delay responding. Here's what's missing in your code: indexMapping.DefaultMapping = newMapping.

When using a geopoint field with bleve, the above line is required to avoid indexing the geo points as numeric values in the _all field. Here's a unit test for reference - https://github.com/blevesearch/bleve/blob/master/search_test.go#L1862. Not specifying the DefaultMapping for the index results in 0 results, similar to what you've observed in your test.

CGenie commented 1 week ago

OK it works, thank you! This is so nice and at the same time extremely fast (I used DuckDB and needed quite some thinking to get the query as performant as bleve).