# Querying based on some dynamic name and quantity, rather than string popularity

**URL:** <https://discuss.elastic.co/t/querying-based-on-some-dynamic-name-and-quantity-rather-than-string-popularity/21265>\
**Category:** Elasticsearch\
**Created:** [December 16, 2014, 3:08am UTC](https://discuss.elastic.co/t/querying-based-on-some-dynamic-name-and-quantity-rather-than-string-popularity/21265 "2014-12-16T03:08:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![am1](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@am1](https://discuss.elastic.co/u/am1)\
**Post date:** [December 16, 2014, 3:08am UTC](https://discuss.elastic.co/t/querying-based-on-some-dynamic-name-and-quantity-rather-than-string-popularity/21265/1 "2014-12-16T03:08:16Z")

</div>

I have a list of specifications per item in my database. I'd like to index  
these specifications and then query them.

The problem is the specifications vary per item type (and even within items  
of the same type), and querying specifications is useful only through  
numerical quantities rather than a tokenized popular word search.

For example, take two items:

Item 1: {

```
"name": "Cool Shirt",
 "item_type": "Clothing",
 "specifications": {
     "nylon": "50 %",
     "elasticity": "max 2 %",
     "cotton": "40 %",
  }

```

}

Item 2: {

```
  "name": "Nail",
  "item_type": "Hardware",
  "specifications": {
       "length": "4 mm",
       "head_diameter: "2mm",
       "steel": "20 %",
  }

```

}

Item 2: {

```
  "name": "Nail",
  "item_type": "Hardware",
  "specifications": {
       "length": "17 mm",
       "head_diameter: "3mm",
       "iron": "10 %",
       "annular_rings": True
  }

```

}

The specifications can vary even within the same item type.

I would like to build queries that ask things like:

```
- Give me all shirts that have a max elasticity of 2%

- Give me all shirts that have at least 40% cotton and nylon that is 

```

between 50%-60%

```
- Give me all nails that have lengths of at least 2 mm and are also at 

```

least 10% steel

And so on...

It is not necessary make ES guess at the specification name. The user will  
input that. So if a user wants to search for clothes with 'nylon', it would  
be something like:

nylon="30%"

And then ES would look for a specification name called 'nylon'. Something  
along those lines.

I looked at aggregations:  
[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html)

But I'm not quite sure how this would apply. It seems aggregations are for  
document fields that are static and not semi-dynamic like in my case.

Are there any suggestions? I was planning on storing all items in one  
document called 'items', but the specifications part is difficult to figure  
out.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/f516c4ad-4b44-4564-b0c2-36d987e01647%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f516c4ad-4b44-4564-b0c2-36d987e01647%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![am1](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@am1](https://discuss.elastic.co/u/am1)\
**Post date:** [December 16, 2014, 3:09am UTC](https://discuss.elastic.co/t/querying-based-on-some-dynamic-name-and-quantity-rather-than-string-popularity/21265/2 "2014-12-16T03:09:33Z")

</div>

I had a typo:

I meant to say 3 items, and the third item should should say 'Item 3' not  
'Item 2'

On Monday, December 15, 2014 10:08:16 PM UTC-5, am wrote:

> I have a list of specifications per item in my database. I'd like to index  
> these specifications and then query them.
> 
> The problem is the specifications vary per item type (and even within  
> items of the same type), and querying specifications is useful only through  
> numerical quantities rather than a tokenized popular word search.
> 
> For example, take two items:
> 
> Item 1: {
> 
> ```
> "name": "Cool Shirt",
> "item_type": "Clothing",
> "specifications": {
> "nylon": "50 %",
> "elasticity": "max 2 %",
> "cotton": "40 %",
> }
> 
> ```
> 
> }
> 
> Item 2: {
> 
> ```
> "name": "Nail",
> "item_type": "Hardware",
> "specifications": {
> "length": "4 mm",
> "head_diameter: "2mm",
> "steel": "20 %",
> }
> 
> ```
> 
> }
> 
> Item 2: {
> 
> ```
> "name": "Nail",
> "item_type": "Hardware",
> "specifications": {
> "length": "17 mm",
> "head_diameter: "3mm",
> "iron": "10 %",
> "annular_rings": True
> }
> 
> ```
> 
> }
> 
> The specifications can vary even within the same item type.
> 
> I would like to build queries that ask things like:
> 
> ```
> - Give me all shirts that have a max elasticity of 2%
> 
> - Give me all shirts that have at least 40% cotton and nylon that is 
> 
> ```
> 
> between 50%-60%
> 
> ```
> - Give me all nails that have lengths of at least 2 mm and are also at 
> 
> ```
> 
> least 10% steel
> 
> And so on...
> 
> It is not necessary make ES guess at the specification name. The user will  
> input that. So if a user wants to search for clothes with 'nylon', it would  
> be something like:
> 
> nylon="30%"
> 
> And then ES would look for a specification name called 'nylon'. Something  
> along those lines.
> 
> I looked at aggregations:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html)
> 
> But I'm not quite sure how this would apply. It seems aggregations are for  
> document fields that are static and not semi-dynamic like in my case.
> 
> Are there any suggestions? I was planning on storing all items in one  
> document called 'items', but the specifications part is difficult to figure  
> out.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/ad0dcdfa-01fb-4f00-afb1-9eba1503cec0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ad0dcdfa-01fb-4f00-afb1-9eba1503cec0%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 12:43am UTC](https://discuss.elastic.co/t/querying-based-on-some-dynamic-name-and-quantity-rather-than-string-popularity/21265/3 "2017-07-06T00:43:37Z")

</div>


