How to select distinct field values using Solr?

前端 未结 6 1074
别跟我提以往
别跟我提以往 2020-11-28 04:01

I would like to do the equivalent of this SQL but with Solr as my data store.

SELECT
   DISTINCT txt
FROM
   my_table;

What syntax would fo

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 04:52

    Faceting would get you a results set that contains distinct values for a field.

    E.g.

    http://localhost:8983/solr/select/?q=*%3A*&rows=0&facet=on&facet.field=txt
    

    You should get something back like this:

    
    02
    
    
     
     
      
            100
            80
            5
            2
            1
      
     
    
    
    

    Check out the wiki for more information. Faceting is a really cool part of solr. Enjoy :)

    http://wiki.apache.org/solr/SimpleFacetParameters#Facet_Fields

    Note: Faceting will show the indexed value, I.e. after all the filters have been applied. One way to get around this is to use the copyfield method, so that you can create a facet version of the txt field. THis way your results will show the original value.

    Hope that helps.. Lots of documentation on faceting available on the wiki. Or I did write some with screen shots.. which you can check out here:

    http://www.craftyfella.com/2010/01/faceting-and-multifaceting-syntax-in.html

提交回复
热议问题