1

I would like to create an output based on the field-names of my Solr index objects.

What I have are objects like this e.g.:

{
    "Id":"ID12345678",
    "GroupKey":"Beta",
    "PricePackage":5796.0,
    "PriceCoupon":5316.0,
    "PriceMin":5316.0
}

Whereby the Price* fields may vary from object to object, some might have more than three of those, some less, however they would be always prefixed with Price.

How can I query Solr to get a list with all field-names prefixed by Price?

I've looked into filters, facets but could not find any clue on how to do this, as all examples - e.g. regex facet - are in regard to the field-value, not the field-name itself. Or at least I could not adapt it to that.

Jook
  • 4,564
  • 3
  • 26
  • 53
  • Do you want to retrieve a list of all field names defined with a name that starts with `Price`, or do you only want the fields that start with `Price` to be included in the response? – MatsLindh Apr 02 '19 at 12:12
  • I want to retrieve a list of all field names defined with a name that starts with Price – Jook Apr 02 '19 at 12:24
  • 2
    You can use the `/solr/collection/admin/luke?wt=json&show=schema` endpoint to retrieve all defined fields for your schema, then filter that further in your application as necessary – MatsLindh Apr 02 '19 at 12:49
  • 2
    ```/solr/myCollection/schema/fields?wt=json``` got me a JSON of all fields, which I could filter as I like with JS, that is already sufficient, thanks! ```/solr/myCollection/schema/fields?fl=PriceMin,Id&wt=json``` works too, however, ```/solr/myCollection/schema/fields?fl=Price*&wt=json``` does not – Jook Apr 02 '19 at 13:13
  • Something else to keep in mind with the schema API (/solr/myCollection/schema/fields) is that it won't report dynamically created fields. – Hector Correa Apr 02 '19 at 13:57

1 Answers1

3

You can get a comma separated list of all existing field names if you query for 0 documents and use the csv response writer (wt parameter) to generate the field name list.

For example if you request /solr/collection/select?q=*:*&wt=csv you get a list of all fields. If you only want fields prefixed with Price you could also add the field list parameter (fl) to limit the fields.

So the request to /solr/collection/select?q=*:*&wt=csv&fl=Price*should return the following response:

PricePackage,PriceCoupon,PriceMin

With this solution you get all fields existing including dynamic fields.

Benjamin P.
  • 453
  • 5
  • 12