0

So I have a solr result with the following JSON:

{
  "grouped": {
    "manu_exact": {
      "matches": 2,
      "groups": [
        {
          "groupValue": "SOLR1000",
          "doclist": {
            "numFound": 2,
            "start": 0,
            "docs": [
              {
                "id": "SOLR1000",
                "name": "Solr, the Enterprise Search Server",
                "date":"March 1, 2018 03:00:00",
                "status":"Cancel"
              },
              {
               "id": "SOLR1000",
                "name": "Solr, the Enterprise Search Server",
                "date":"March 1, 2018 01:00:00",
                "status":"New"
              }

            ]
          }
        },
        {
          "groupValue": "VS1GB400C3",
          "doclist": {
            "numFound": 2,
            "start": 0,
            "docs": [
              {
                "id": "VS1GB400C3",
                "name": "Retail",
                "date":"March 4, 2018 04:00:00",
                "status":"Shipped"
              },
              {
                "id": "VS1GB400C3",
                "name": "Retail",
                "date":"March 4, 2018 02:00:00",
                "status":"New"
              }
            ]
          }
        }
      ]
    }
  }
}

The field definitions of the relevant fields are:

<field name="id" type="string" indexed="true" stored="true" required="true" /> 
<field name="date" type="tdate" indexed="true" stored="true"/>
<field name="status" type="string" indexed="true" stored="true"/>

The field types of "string" and "tdate" types are as follows:

<fieldType name="string" class="solr.StrField"
      positionIncrementGap="100"/></fieldType>
<fieldType name="tdate" class="solr.TrieDateField" precisionStep="6" 
      positionIncrementGap="0"/></fieldType>

The above query is generated by the following grouping parameter:

group=true& group.field=id& group.sort=date desc & group.limit=10

I wish to do the following:

Run a query that includes only includes those groups that contain documents that are not "cancelled".

Basically, the sorted group gives the time line of the status of the product. I only want to retrive the documents that do not have the latest status as "Cancel".

This is done by sorting the group by the date field and checking the status of the first document.

In the above example, I do not want to include the first group as the status field of its latest document has value : "cancel".

However I want the second group to be included as the status field of its latest document has value : "shipped" and not "cancel".

Any ideas how to do this?

Any help would be much appreciated.

  • Essentially, what Solr does is that it performs grouping after the documents have been retrieved. Hence I want to perform a check on the first document on each group and include the group in the result based on a value of the field in that first document. If the value of "status" field of the first document of each sorted group is NOT "Cancel" then include that group, else exclude it. – Anirudha Nanda Apr 02 '18 at 15:26
  • Could you do [a collapse](https://lucene.apache.org/solr/guide/6_6/collapse-and-expand-results.html#collapse-and-expand-results) and then apply the requirement? i.e. `&fq={!collapse field=id max=date}*:* -status:Cancel` (or if necessary, split it into separate `fq` terms, one for the collapse and one for the actual filtering). – MatsLindh Apr 02 '18 at 18:34
  • @MatsLindh thanks for your response! I am running into the following error when I try the following : fq={!collapse field=id} "64-Bit numberic collapse fields are not supported". Please note that my id field is a string and not a number. In such cases how should the collapse field look like? – Anirudha Nanda Apr 02 '18 at 19:21
  • Is it a string field or a TextField? What is the exact definition? – MatsLindh Apr 02 '18 at 19:24
  • Its a string field with the following config : indexed=true and stored=true – Anirudha Nanda Apr 02 '18 at 19:35
  • Add the _exact_ definition of the field and the field type to your question. Has the field type been changed at any time without completly clearing out the index and reindexing? Does it work with a different field name? – MatsLindh Apr 02 '18 at 19:53
  • Hi @MatsLindh please find the definition: – Anirudha Nanda Apr 02 '18 at 20:03
  • But neither of those are the definition of what the field type `string` is. It might not be `StrField`, since you're getting that error. The error is explicitly triggered when the field you're trying to collapse isn't a StrField based type, or a Int/Float type. So it's important to try to find out why that happens. For the `tdate` type it's probably because it doesn't map to either of those types, but indexing the date as an integer timestamp would solve that (but since you're saying you're getting the error when _just_ referencing `id`, the error should not be related to that at the moment). – MatsLindh Apr 02 '18 at 20:05
  • hi @MatsLindh you were right earlier about field definition. I have since updated the field definitions. Turns out the string field is indeed of type StrField :( – Anirudha Nanda Apr 02 '18 at 20:22

0 Answers0