Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A ValueSource isn't directly available from this field response for geodist() query [DATASOLR-511] #629

spring-projects-issues opened this issue Mar 4, 2019 · 3 comments


Copy link

@spring-projects-issues spring-projects-issues commented Mar 4, 2019

Vigneshwaran opened DATASOLR-511 and commented

While trying to use geodist() query via Spring data solr, we are getting "A ValueSource isn't directly available from this field" error response

Code for generating geodist function

Point point = new Point(42.9254,78.8696)
Criteria criteria = new Criteria()
criteria.function(new GeoDistanceFunction.Builder(new SimpleField('latLong')).to(point)) 

SimpleQuery query = new SimpleQuery(criteria)
  .addSort(new Sort(Sort.Direction.ASC, 'score'))

// Field in schema
<field name="latLong" type="location" indexed="true" stored="true" required="true"/>

<fieldType name="location" class="solr.LatLonPointSpatialField" docValues="true"/>


SolrQuery generated by SolrTemplate internally


Actual Query expected by Solr




Reference URL:


Referenced from: commits 0fd9dba, 6a30aa1, 91d570e

Copy link

@spring-projects-issues spring-projects-issues commented Mar 8, 2019

Christoph Strobl commented

That is actually a tricky one. According to Solr Reference for geodist it is still defined as

a distance function that takes three optional parameters: (sfield,latitude,longitude)

However looking at Apache Solr code, the computation there now just throws an exception.

So there's different scenarios to cover here:

  • geodist() as query criteria influencing score
  • geodist() as a filter query without affecting document score
  • obtain the distance when filtered
  • sort by distance

I've pushed a branch that should cover those scenarios. If you've got the time please consider giving it a try.
The artifact (spring-data-solr:4.1.0.DATASOLR-511-SNAPSHOT) is available via

// -> /select?q={!func}geodist()&sfield=store&pt=45.15,-93.85&fl=*,score    

Query q = Query.query(Criteria.where(GeoDistanceFunction.distanceFrom("store").to(new Point(45.15, -93.85))))

// -> /select?q=*:*&fq={!func}geodist()&sfield=store&pt=45.15,-93.85&fl=*,distance:geodist()  

Query q = Query.all()
    .addFilterQuery(FilterQuery.geoFilter("store", new Point(45.15, -93.85)))
// -> /select?q=*:*&fq={!func}geodist()&sfield=store&pt=45.15,-93.85&sort=geodist+asc

Query q = Query.all()
    .addFilterQuery(FilterQuery.geoFilter("store", new Point(45.15, -93.85)))
Copy link

@spring-projects-issues spring-projects-issues commented May 7, 2019

Bassem commented

Christoph Strobl, I am also facing the same issue as described in this case. I have tried your suggested solution above, but it seems that the following artifact does not includes the changes. Your help is appreciated.  


!2019-05-07 10_58_43-solr.png!


Copy link

@spring-projects-issues spring-projects-issues commented May 13, 2019

Christoph Strobl commented

Fawzi the changes have not been merged yet. Will do soon, so they can be released with M4 then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants