0

I want to sort solr result by sku,

Here is my query to sort result

http://localhost:8983/solr/test_core/select?sort=skucode+asc&q=*skucode*&wt=xml

skucode tag stored data in numeric field.

<str name="id">39902395</str>
<arr name="skucode"><long>5076501</long></arr>

I have stored data in solr using xml file.

It gives error that can not sort on multivalued field: skucode

Or Store data without multivalued

Please let me know how to store data without multivalued or how to change from backend.

Rahul
  • 763
  • 1
  • 12
  • 45

1 Answers1

0

Your query will work only if the field on which you are performing sorting is single valued not multi-valued. You can use function query to perform sort on multi-valued field.

http://localhost:8983/solr/test_core/select?sort=field(skucode,max)+ASC&q=*skucode*&wt=xml

For more Information on function query :- https://cwiki.apache.org/confluence/display/solr/Function+Queries

The second approach in which the query that are you using will also work is that you can change the data type for skucode and make it single value. To make it single value change data-type for skucode from longs to long in schema.xml.

<field name="skucode" type="long"/>

P.S :- After changing its data-type you need to re-index to reflect your changes

Sanjay Dutt
  • 2,192
  • 16
  • 16
  • 1
    where is location of schema.xml file – Rahul Jul 06 '17 at 05:34
  • @RahulDambare If you are running Solr in cloud mode then configuration files will be in zookeeper. But If you are running single core then it will be in **Solr-home/server/solr/test_core/conf/managed-schema.xml** – Sanjay Dutt Jul 06 '17 at 05:51