BJ Wright
BJ Wright

Reputation: 1

Solr return new column derived from calculated value of 2 columns in document

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

Answers (2)

Akhilesh
Akhilesh

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

Alexandre Rafalovitch
Alexandre Rafalovitch

Reputation: 9789

Have you tried FunctionQuery? Seems like a good match to your needs. You can do all sorts of derived expressions.

Upvotes: 1

Related Questions