Skip to content

Instantly share code, notes, and snippets.

@xou
Created January 7, 2016 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xou/33fd7aab7afe3cebb28b to your computer and use it in GitHub Desktop.
Save xou/33fd7aab7afe3cebb28b to your computer and use it in GitHub Desktop.
<enumsConfig>
<enum name="auState">
<value>ACT</value>
<value>NSW</value>
<value>NT</value>
<value>QLD</value>
<value>SA</value>
<value>TAS</value>
<value>VIC</value>
<value>WA</value>
</enum>
</enumsConfig>
<?xml version="1.0" encoding="UTF-8" ?>
<schema name="facet-bug" version="0.1">
<field name="id" type="long" indexed="true" required="true" stored="true" multiValued="false" />
<field name="name" type="cistring" indexed="true" stored="true" multiValued="false" />
<field name="state" type="auState" indexed="true" multiValued="false" docValues="true" />
<field name="insertdate" type="date" indexed="true" multiValued="false" />
<fieldType name="date" class="solr.TrieDateField" />
<fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="cistring" class="solr.TextField" sortMissingLast="true">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.ReversedWildcardFilterFactory" />
</analyzer>
<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.ReversedWildcardFilterFactory" />
</analyzer>
</fieldType>
<fieldType name="auState" class="solr.EnumField" enumsConfig="enumConfig.xml" enumName="auState" />
<uniqueKey>id</uniqueKey>
<defaultSearchField>name</defaultSearchField>
</schema>
<?xml version="1.0" encoding="UTF-8" ?>
<config>
<luceneMatchVersion>5.2.0</luceneMatchVersion>
<requestHandler name="standard" class="solr.SearchHandler" default="true">
<lst name="defaults">
<str name="echoParams">explicit</str>
<int name="rows">100</int>
<str name="fl">*</str>
<str name="version">2.1</str>
</lst>
</requestHandler>
</config>
[
{
"id":2,
"name":"asd",
"state":"QLD"},
{
"id":3,
"name":"asd",
"state":"WA"},
{
"id":1,
"state":"QLD",
"name":"HelloWorld",
"insertdate":"2016-01-06T23:37:36.655Z"},
{
"id":12,
"state":"QLD",
"name":"HelloWorld2",
"insertdate":"2016-01-06T23:37:48.023Z"}]
"First testrun (using facet.field) works, second one (using JSON api) does not"
curl http://localhost:8983/solr/core1/select -d 'q=*:*&wt=json&indent=true&facet=on&rows=0&facet.field=state&facet.field=insertdate'
{
"responseHeader":{
"status":0,
"QTime":20,
"params":{
"q":"*:*",
"facet.field":["state",
"insertdate"],
"indent":"true",
"rows":"0",
"wt":"json",
"facet":"on"}},
"response":{"numFound":4,"start":0,"docs":[]
},
"facet_counts":{
"facet_queries":{},
"facet_fields":{
"state":[
"QLD",3,
"WA",1],
"insertdate":[
"2016-01-06T23:37:36.655Z",1,
"2016-01-06T23:37:48.023Z",1]},
"facet_dates":{},
"facet_ranges":{},
"facet_intervals":{},
"facet_heatmaps":{}}}
curl http://localhost:8983/solr/core1/select -d 'q=*:*&wt=json&indent=true&rows=10&
json.facet={
states: {field: state}, dates: {field: insertdate}
}'
{
"responseHeader":{
"status":400,
"QTime":12,
"params":{
"q":"*:*",
"json.facet":"{\n states: {field: state}, dates: {field: insertdate}\n}",
"indent":"true",
"rows":"10",
"wt":"json"}},
"response":{"numFound":4,"start":0,"docs":[
{
"id":2,
"name":"asd",
"state":"QLD"},
{
"id":3,
"name":"asd",
"state":"WA"},
{
"id":1,
"state":"QLD",
"name":"HelloWorld",
"insertdate":"2016-01-06T23:37:36.655Z"},
{
"id":12,
"state":"QLD",
"name":"HelloWorld2",
"insertdate":"2016-01-06T23:37:48.023Z"}]
},
"error":{
"msg":"Expected numeric field type :state{type=auState,properties=indexed,stored,docValues}",
"code":400}}
@xou
Copy link
Author

xou commented Jan 7, 2016

It works when the enum field is dropped from the JSON query:

~/d/s/l/solr ❯❯❯ curl http://localhost:8983/solr/core1/select -d 'q=*:*&wt=json&indent=true&rows=10&
json.facet={
  dates: {field: insertdate}
}'
{
  "responseHeader":{
    "status":0,
    "QTime":1,
    "params":{
      "q":"*:*",
      "json.facet":"{\n  dates: {field: insertdate}\n}",
      "indent":"true",
      "rows":"10",
      "wt":"json"}},
  "response":{"numFound":4,"start":0,"docs":[
      {
        "id":2,
        "name":"asd",
        "state":"QLD"},
      {
        "id":3,
        "name":"asd",
        "state":"WA"},
      {
        "id":1,
        "state":"QLD",
        "name":"HelloWorld",
        "insertdate":"2016-01-06T23:37:36.655Z"},
      {
        "id":12,
        "state":"QLD",
        "name":"HelloWorld2",
        "insertdate":"2016-01-06T23:37:48.023Z"}]
  },
  "facets":{
    "count":4,
    "dates":{
      "buckets":[{
          "val":"2016-01-06T23:37:36.655Z",
          "count":1},
        {
          "val":"2016-01-06T23:37:48.023Z",
          "count":1}]}}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment