# Store and query generic attributes/fields

**URL:** <https://discuss.elastic.co/t/store-and-query-generic-attributes-fields/248671>\
**Category:** Elasticsearch\
**Created:** [September 15, 2020, 12:25pm UTC](https://discuss.elastic.co/t/store-and-query-generic-attributes-fields/248671 "2020-09-15T12:25:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ggrune](https://avatars.discourse-cdn.com/v4/letter/g/d78d45/32.png) [@ggrune](https://discuss.elastic.co/u/ggrune)\
**Post date:** [September 15, 2020, 12:25pm UTC](https://discuss.elastic.co/t/store-and-query-generic-attributes-fields/248671/1 "2020-09-15T12:25:24Z")

</div>

We have a software that allows custom attributes for products.  
Example:

```auto
   "products" : [
    {
    	"id" : "222222",
    	"sku" : "12345",
    	"name" : "Fancy notebook",
    	"category" : "computer",
    	...
    	"attributes": {
    		"Power_consumption" : "220 W",
    		"Power_requirements" : "AC 100-240V@50-60Hz",
    		"Processor_model" : "Intel Xeon",
    		"Power_supply" : "700 W",
    		"Networking_features" : "10 Gigabit Ethernet",
    		"Ethernet_LAN_(RJ-45)_ports_quantity" : "2",
    		"Weight" : {
    			"unit" : "g",
    			"value" : 2800
    		},
    		"Certification" : "FCC, CE, C-Tick, KCC, VCCI, CCC, RoHS, WEEE",
    		"USB_2_0_ports_quantity" : "2",
    		"Hard_disk_interface" : "Serial ATA"
    		...
    	}
    },
    "product" : {
    	"id" : "111111",
    	"sku" : "23456",
    	"name" : "Network cable",
    	"category" : "accessories",
    	...
    	"attributes": {
    		"Connector_2" : "RJ45",
    		"Connector_1" : "RJ45",
    		"Material" : "ABS synthetics",
    		"Weight" : {
    			"unit" : "g",
    			"value" : 40
    		},
    		"Colour_of_product" : "Black",
    		"Cable_length" : {
    			"unit" : "m",
    			"value" : "1.5 m"
    		}
    		...
    	}
    },
...
]

```

I have tried to index 2800 of our demo products strait forward. After increasing the `index.mapping.total_fields.limit` to 7000 the process finished without errors.  
7000 total fields doesn't feel right and with \>500 000 products this value will be much higher.  
Is there a better way to store and search such data structure? This problem looks like very common for online shops and product information systems, so I would expect a solution. But as far I didn't find one. May be I am blind 🙂  
All solution, hints suggestions are welcome.

---

<div class="post-metadata">

**Author:** ![ylasri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ylasri/32/86120_2.png) [@ylasri](https://discuss.elastic.co/u/ylasri)\
**Post date:** [September 15, 2020, 12:40pm UTC](https://discuss.elastic.co/t/store-and-query-generic-attributes-fields/248671/2 "2020-09-15T12:40:32Z")

</div>

I would use an array of nested attributes like : key, unit & value

```
{
  "attributes": [
    {
      "key": "Power_consumption",
      "value": "220 W"
    },
    {
      "key": "Power_requirements",
      "value": "AC 100-240V@50-60Hz"
    },
    {
      "key": "Weight",
      "unit": "g",
      "value": 2800
    }
  ]
}
```

---

<div class="post-metadata">

**Author:** ![ggrune](https://avatars.discourse-cdn.com/v4/letter/g/d78d45/32.png) [@ggrune](https://discuss.elastic.co/u/ggrune)\
**Post date:** [September 15, 2020, 2:57pm UTC](https://discuss.elastic.co/t/store-and-query-generic-attributes-fields/248671/3 "2020-09-15T14:57:02Z")

</div>

This only works if all values have the same type. I can convert all values to text, with the drawback of losing type information and functionality (e.g. query a long value that is lesser or greater, dates before, ...).

---

<div class="post-metadata">

**Author:** ![ylasri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ylasri/32/86120_2.png) [@ylasri](https://discuss.elastic.co/u/ylasri)\
**Post date:** [September 15, 2020, 2:58pm UTC](https://discuss.elastic.co/t/store-and-query-generic-attributes-fields/248671/4 "2020-09-15T14:58:41Z")

</div>

Yes of course 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 13, 2020, 2:58pm UTC](https://discuss.elastic.co/t/store-and-query-generic-attributes-fields/248671/5 "2020-10-13T14:58:53Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
