0

we are using solr 7.5, we have implemented dynamic fields for products attribute, now we are facing the problem in doing the facets on dynamic filed.

following are the product documents for the dynamic field

<dynamicField name="*_attribute" type="text_general" multiValued="true" indexed="true" stored="true"/>

{
"product_slno":"1",
"product_name":["baby doll"],
"text":["baby doll"],
"color_attribute":["red1"],
"type_attribute":["xyz1"],
"material_attribute":["plastic1"],
"_version_":1660058653347020800},
{
"product_slno":"2",
"product_name":["babydoll"],
"text":["babydoll"],
"color_attribute":["red"],
"style_attribute":["xyz"],
"material_attribute":["plastic"],
"_version_":1660058653383720960
},

for example if we want to get the color_attribute value for entire document the we are not able to geet it.

and we do not have the fixed attribute for any products so we are trying to use dynamic fields

please help
  • Using `text_general` fields for facets isn't a good idea, as they will be tokenized (i.e. `dark yellow` would be split into `dark` and `yellow`). Other than that, there is nothing special about dynamic fields. You can facet on `color_attribute` as you'd facet on any other field. – MatsLindh Mar 04 '20 at 10:15
  • thanks a lot what i want to do is get all facet count for dynamic fields using (facet.field=*) is it possible o there is other way for doing like this /solr/products/select?q=product_name:babydoll&rows=0&facet=true&facet.limit=500&facet.mincount=1&facet.field=*&indent=on – abhay patel Mar 04 '20 at 10:22
  • 1
    As far as I know there is no wildcard support for `facet.field`. But some place you probably have metadata about which dynamic fields can exist (in your own application); I'd extract those and create separate `facet.field` entries for each. This will also allow you to tag them appropriately if you want to exclude filters based on tags (so that you can have total facet counts independent of the filters applied to the search result itself). – MatsLindh Mar 04 '20 at 10:34
  • This answer https://stackoverflow.com/a/29546298 tells you how to query for the list of all fields (including the dynamic ones). – Ian Goldby Nov 04 '22 at 15:47

1 Answers1

0

You need to change the field type for your faceting fields. Its would be good if you use the string as your field type for you faceting fields. The tokenization is not good for faceting. As you are using the text_general for your field. You need to change the same.

As the string type will have no tokenization of the text, and used as single token for faceting.

You can have a separate field for as below for faceting.

<dynamicField name="*_facet_attribute" type="string" multiValued="true" indexed="true" stored="true"/>

You can have it as dynamic field or a normal field as well.

Abhijit Bashetti
  • 8,518
  • 7
  • 35
  • 47
  • thanks a lot now i have changed it from "text_general" to "string" what i want to do is to get all facet count for dynamic fields using (facet.field=*) is it possible or there is other way for doing like this /solr/products/select?q=product_name:babydoll&rows=0&facet=true&facet.limit=500&facet.mincount=1&facet.field=*&indent=on – abhay patel Mar 04 '20 at 10:24
  • You have to specify each facet field in your query; you can't use a wildcard like you do in dynamicField. You can get a list of all fields (including the dynamic ones) - see https://stackoverflow.com/a/29546298 – Ian Goldby Nov 04 '22 at 15:45