Reputation: 1
Is it possible with Solr to do a calculation based off two fields in the document and return that calculated value as a new field.
for example I have several fields of integer type
<field name="baseData" type="integer" indexed="true" stored="true"/>
<field name="altData" type="integer" indexed="true" stored="true"/>
<field name="altData2" type="integer" indexed="true" stored="true"/>
I need to query the solr server to get these fields, and return an additional field that is the combined value (baseData - altData). This returned value could also be (baseData - altData2) depending on the query.
I cannot preload this field into the document as I will not know which field to add to baseData until I form the query. Although this example only has a few columns the project requirements could be combining baseData with any of many other values.
I think I need to get the data from Solr like this so I can do things like sorting on the newly combined field
I have had no luck finding any documentation on how to do this if it is possible.
Upvotes: 0
Views: 2535
Reputation: 57
localhost:8983/solr/collection1/select?indent=on&q=:&wt=json&fl=altDate3:sub(baseData,altData)
try these, i think it helps you.
Upvotes: 1
Reputation: 9789
Have you tried FunctionQuery? Seems like a good match to your needs. You can do all sorts of derived expressions.
Upvotes: 1