I'm trying to use faceting to look at the terms that were indexed into a field, realizing this is a bit atypical, but I'm using it as a debugging tool. The problem is I'm not seeing any faceted terms.
I think this is something to do with later version of Solr, perhaps v8 or v9, but not finding any reference to that. I do have a shell script that reproduces the problem pretty easily:
#!/bin/bash
COLLECTION=test
NUM_SHARDS=1 # Solr v9 (maybe earlier) doesn't restrict to single shard, BUT doesn't matter for our small dataset
TERMS=test
TYPE=text_general
SUFFIX=_t
FIELD=test$SUFFIX
DOC_ID=doc1
echo;echo
echo Removing Any Previous collection - will give error if run for the first time
curl "http://localhost:8983/solr/admin/collections?action=DELETE&name=$COLLECTION"
echo;echo
echo Creating Collection $COLLECTION with $NUM_SHARDS shards
curl "http://localhost:8983/solr/admin/collections?action=CREATE&name=$COLLECTION&numShards=$NUM_SHARDS&replicationFactor=1&maxShardsPerNode=$NUM_SHARDS"
echo;echo
echo Adding doc id = $DOC_ID with TERMS = $TERMS
curl -X POST "http://localhost:8983/solr/$COLLECTION/update?commit=true" \
-H "Content-Type: application/json" \
-d "[
{
\"id\": \"$DOC_ID\",
\"$FIELD\": \"this is a test of the Solr indexing system: TERMS = $TERMS\"
}
]"
echo;echo
echo Query for all docs
curl "http://localhost:8983/solr/$COLLECTION/select?q=*:*"
echo;echo
echo Query for TERMS = $TERMS
curl "http://localhost:8983/solr/$COLLECTION/select?defType=edismax&qf=$FIELD&q=$TERMS&rows=1"
echo;echo
echo Testing Old Facet API
curl "http://localhost:8983/solr/$COLLECTION/select?q=*:*&rows=0&facet=true&facet.field=$FIELD"
echo;echo
echo Testing New Facet API
curl "http://localhost:8983/solr/$COLLECTION/select?q=*:*&rows=0&json.facet=%7Bwords:%7Btype:terms,field:content_t,limit:10%7D%7D"
echo;echo
echo Done
If I put an echo in front of my curl command that inserts the document you can see that the variable substitution looks correct:
curl -X POST http://localhost:8983/solr/my-files/update?commit=true -H Content-Type: application/json -d [
{
"id": "doc1",
"test_t": "this is a test of the Solr indexing system: TERMS = test"
}
]
Then doing a null query you can see that the document is ndexed:
Query for all docs
{
"responseHeader":{
"zkConnected":true,
"status":0,
"QTime":0,
"params":{
"q":"*:*"
}
},
"response":{
"numFound":1,
"start":0,
"numFoundExact":true,
"docs":[ ]
}
}
Searching for the terms seems to work:
{
"responseHeader":{
"zkConnected":true,
"status":0,
"QTime":0,
"params":{
"q":"test",
"defType":"edismax",
"qf":"test_t",
"rows":"1"
}
},
"response":{
"numFound":1,
"start":0,
"numFoundExact":true,
"docs":[{
"id":"doc1",
"test_t":"this is a test of the Solr indexing system: TERMS = test",
"_version_":1847191228405252096,
"_root_":"doc1"
}]
}
But notice what happens when I try to facet:
echo;echo
echo Testing Old Facet API
curl "http://localhost:8983/solr/$COLLECTION/select?q=*:*&rows=0&facet=true&facet.field=$FIELD"
Gives the output:
Testing Old Facet API
{
"responseHeader":{
"zkConnected":true,
"status":0,
"QTime":0,
"params":{
"q":"*:*",
"facet.field":"test_t",
"rows":"0",
"facet":"true"
}
},
"response":{
"numFound":1,
"start":0,
"numFoundExact":true,
"docs":[ ]
},
"facet_counts":{
"facet_queries":{ },
"facet_fields":{
"test_t":[ ]
},
"facet_ranges":{ },
"facet_intervals":{ },
"facet_heatmaps":{ }
}
}
Similar results if I try the newer JSON syntax:
echo;echo
echo Testing New Facet API
curl "http://localhost:8983/solr/$COLLECTION/select?q=*:*&rows=0&json.facet=%7Bwords:%7Btype:terms,field:content_t,limit:10%7D%7D"