# Facet-Search property/property-value

**URL:** <https://discuss.elastic.co/t/facet-search-property-property-value/6097>\
**Category:** Elasticsearch\
**Created:** [December 8, 2011, 10:02am UTC](https://discuss.elastic.co/t/facet-search-property-property-value/6097 "2011-12-08T10:02:11Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![maik](https://avatars.discourse-cdn.com/v4/letter/m/7feea3/32.png) [@maik](https://discuss.elastic.co/u/maik)\
**Post date:** [December 8, 2011, 10:02am UTC](https://discuss.elastic.co/t/facet-search-property-property-value/6097/1 "2011-12-08T10:02:11Z")

</div>

Hi,

I'm evaluating es for our ecommerce enivironment and ran in a problem:

I want to use es with its facet search for building the frontend filters.  
For example: The user could browse some usb sticks and filter all sticks on  
"capacity" with the value "4 GB".  
I need the list of possible properties and its values to build the html.

A product could look like this:

product {  
properties : {  
capacity : "4 GB"  
speed : "32 MB/s"  
}  
name : "very good usb stick"  
}

The properties of course differ with each product.  
A result I'm searching for could be:

results {  
property-facet : {  
...  
...  
facets : [  
{ {property: "capacity", value: "4 GB"}, count: 455 },  
{ {property: "capacity", value: "8 GB"}, count: 133 }

```
  ]  
}

```

}

Is there any way to do this with es?  
Perhaps with another data schema?

Thx in advance  
Greetings  
maik

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [December 8, 2011, 10:22am UTC](https://discuss.elastic.co/t/facet-search-property-property-value/6097/2 "2011-12-08T10:22:07Z")

</div>

The schema is good. Did you already tried the term facets?

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Or what are you after?

Regards,  
Peter.

On 8 Dez., 11:02, maik [maik2...@googlemail.com](mailto:maik2...@googlemail.com) wrote:

> Hi,
> 
> I'm evaluating es for our ecommerce enivironment and ran in a problem:
> 
> I want to use es with its facet search for building the frontend filters.  
> For example: The user could browse some usb sticks and filter all sticks on  
> "capacity" with the value "4 GB".  
> I need the list of possible properties and its values to build the html.
> 
> A product could look like this:
> 
> product {  
> properties : {  
> capacity : "4 GB"  
> speed : "32 MB/s"  
> }  
> name : "very good usb stick"
> 
> }
> 
> The properties of course differ with each product.  
> A result I'm searching for could be:
> 
> results {  
> property-facet : {  
> ...  
> ...  
> facets : [  
> { {property: "capacity", value: "4 GB"}, count: 455 },  
> { {property: "capacity", value: "8 GB"}, count: 133 }
> 
> ```
> ]
> }
> 
> ```
> 
> }
> 
> Is there any way to do this with es?  
> Perhaps with another data schema?
> 
> Thx in advance  
> Greetings  
> maik

---

<div class="post-metadata">

**Author:** ![maik](https://avatars.discourse-cdn.com/v4/letter/m/7feea3/32.png) [@maik](https://discuss.elastic.co/u/maik)\
**Post date:** [December 8, 2011, 3:07pm UTC](https://discuss.elastic.co/t/facet-search-property-property-value/6097/3 "2011-12-08T15:07:53Z")

</div>

Hello Peter,

yes I tried the term facet.  
Perhaps I'm missing some details about it, but I could not discover how to  
configure a term facet to use the dynamic combination of a property and its  
values.

If there was a field like this:  
{  
tags: ["a", "b", "c"]  
}

the facet looks like this:  
"facets" : {  
"tag" : {  
"terms" : {  
"field" : "tag"  
}  
}  
}

But how to configure it, if the tags are not a single string, but a  
document like this: tags : [{property: "capacity", value: "4 GB"},  
{property: "speed", value: "32 MB/s"}]?  
In this case the key is the document and not a single string.

Its difficult for me to describe the Problem in english, but I hope you  
understand it 🙂

Greetings  
maik

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [December 9, 2011, 10:57am UTC](https://discuss.elastic.co/t/facet-search-property-property-value/6097/4 "2011-12-09T10:57:33Z")

</div>

did you try "field" : "tags.property" ?

Peter.

---

<div class="post-metadata">

**Author:** ![maik](https://avatars.discourse-cdn.com/v4/letter/m/7feea3/32.png) [@maik](https://discuss.elastic.co/u/maik)\
**Post date:** [December 9, 2011, 11:13am UTC](https://discuss.elastic.co/t/facet-search-property-property-value/6097/5 "2011-12-09T11:13:43Z")

</div>

Yes, but this only results in something like that:

facets : [  
"capacity": 100,  
"speed": 150  
]

There is no connection to the value, and this is needed.

I helped me out in a way i don't like:  
properties : ["capacity###4 GB", "speed###32 MB/s"]

A facet on the properties field results like this:  
facets: [  
"capacity###4 GB" : 30,  
"capacity###8 GB" : 20,  
"speed###16 MB/s": 10,  
"speed###32 MB/s" : 40  
]

I have to split the properties and values in the application with the  
split-argument "###".  
Thats not very fast.

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [December 9, 2011, 11:27am UTC](https://discuss.elastic.co/t/facet-search-property-property-value/6097/6 "2011-12-09T11:27:08Z")

</div>

> There is no connection to the value, and this is needed.

I see, hmmh but IMO this is a valid approach. Normally you could try  
scripting but in this case not

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

> Thats not very fast.

Do not overestimate this or did you measure it :)?

Peter.

On 9 Dez., 12:13, maik [maik2...@googlemail.com](mailto:maik2...@googlemail.com) wrote:

> Yes, but this only results in something like that:
> 
> facets : [  
> "capacity": 100,  
> "speed": 150  
> ]
> 
> There is no connection to the value, and this is needed.
> 
> I helped me out in a way i don't like:  
> properties : ["capacity###4 GB", "speed###32 MB/s"]
> 
> A facet on the properties field results like this:  
> facets: [  
> "capacity###4 GB" : 30,  
> "capacity###8 GB" : 20,  
> "speed###16 MB/s": 10,  
> "speed###32 MB/s" : 40  
> ]
> 
> I have to split the properties and values in the application with the  
> split-argument "###".  
> Thats not very fast.

---

<div class="post-metadata">

**Author:** ![maik](https://avatars.discourse-cdn.com/v4/letter/m/7feea3/32.png) [@maik](https://discuss.elastic.co/u/maik)\
**Post date:** [December 9, 2011, 11:39am UTC](https://discuss.elastic.co/t/facet-search-property-property-value/6097/7 "2011-12-09T11:39:21Z")

</div>

i didnt measure it. 🙂  
In my prototype its fast enough, but i dont like the way.

Es is a document orientated datastore and i hoped it could solve this issue  
without this splitting thing.

As I can see, es today can only do faceted search on keys, which are are  
single token (like the tag example).  
It would be great if someday hole documents could be key, so my problem  
will be natively solved without doing something strange.

I hoped I only missed the feature in the documentation.

Thx peter for your help.

Greetings  
maik

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [December 9, 2011, 11:42am UTC](https://discuss.elastic.co/t/facet-search-property-property-value/6097/8 "2011-12-09T11:42:48Z")

</div>

On Fri, 2011-12-09 at 03:13 -0800, maik wrote:

> Yes, but this only results in something like that:
> 
> facets : [  
> "capacity": 100,  
> "speed": 150  
> ]

Why not have two facets, one for tags.property.capacity and one for  
tags.property.speed

that should give you what you want

clint

---

<div class="post-metadata">

**Author:** ![maik](https://avatars.discourse-cdn.com/v4/letter/m/7feea3/32.png) [@maik](https://discuss.elastic.co/u/maik)\
**Post date:** [December 9, 2011, 12:00pm UTC](https://discuss.elastic.co/t/facet-search-property-property-value/6097/9 "2011-12-09T12:00:47Z")

</div>

Hi clint,

that would be the way, if I only want to count the properties.  
But I need the property- / property-value combination.

Beside, with your approach I have to know every combination before building  
the search request.

greets  
maik

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [December 9, 2011, 10:47pm UTC](https://discuss.elastic.co/t/facet-search-property-property-value/6097/10 "2011-12-09T22:47:36Z")

</div>

You can't do generic property name / generic property value faceting, aside  
from maybe using scripting (depends on exactly what you are after). But, I  
think from your question that you know that you want to facet on something  
like property name of capacity, no? If so, why not index the property name  
as part of the json field name and facet on it? Or do you want to get all  
the facets for all the properties defined for all the products?

On Fri, Dec 9, 2011 at 2:00 PM, maik [maik2102@googlemail.com](mailto:maik2102@googlemail.com) wrote:

> Hi clint,
> 
> that would be the way, if I only want to count the properties.  
> But I need the property- / property-value combination.
> 
> Beside, with your approach I have to know every combination before  
> building the search request.
> 
> greets  
> maik

---

<div class="post-metadata">

**Author:** ![maik](https://avatars.discourse-cdn.com/v4/letter/m/7feea3/32.png) [@maik](https://discuss.elastic.co/u/maik)\
**Post date:** [December 12, 2011, 7:15am UTC](https://discuss.elastic.co/t/facet-search-property-property-value/6097/11 "2011-12-12T07:15:38Z")

</div>

Hi kimchy,

no I don't know what exactly properties I have to facet on.  
I used some examples here to show you how the properties COULD look like in  
my product-documents.  
Alle products have different properties and values, some more, some less.

I only have a set of products (result of the search) and need all the  
combinations of the properties/values to generate the frontend filters.

So, to make it visual:  
A customer searched for "usb stick", gets the search result with a list of  
products and additionally these filters on the side:

[https://lh3.googleusercontent.com/-tGBltZbDsQw/TuWplIH9h3I/AAAAAAAAAww/rEdW5aqVj9E/s1600/Bildschirmfoto%25202011-12-12%2520um%252008.13.27.png](https://lh3.googleusercontent.com/-tGBltZbDsQw/TuWplIH9h3I/AAAAAAAAAww/rEdW5aqVj9E/s1600/Bildschirmfoto%2525202011-12-12%252520um%25252008.13.27.png)

I thought es could bring the data for this filters with its facet search.

Greetings

maik

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [December 12, 2011, 1:08pm UTC](https://discuss.elastic.co/t/facet-search-property-property-value/6097/12 "2011-12-12T13:08:15Z")

</div>

Since we have the mapping information, we might be able to do this, i.e.  
automatically generate facets for all the properly names assuming they are  
used as field names. But, you can also do it yourself, you can ask for the  
mapping, it will include all the fields names options, and build the facets  
request based on that. (note, the properly names will need to be fields in  
the document).

On Mon, Dec 12, 2011 at 9:15 AM, maik [maik2102@googlemail.com](mailto:maik2102@googlemail.com) wrote:

> Hi kimchy,
> 
> no I don't know what exactly properties I have to facet on.  
> I used some examples here to show you how the properties COULD look like  
> in my product-documents.  
> Alle products have different properties and values, some more, some less.
> 
> I only have a set of products (result of the search) and need all the  
> combinations of the properties/values to generate the frontend filters.
> 
> So, to make it visual:  
> A customer searched for "usb stick", gets the search result with a list of  
> products and additionally these filters on the side:
> 
> [https://lh3.googleusercontent.com/-tGBltZbDsQw/TuWplIH9h3I/AAAAAAAAAww/rEdW5aqVj9E/s1600/Bildschirmfoto%2525202011-12-12%252520um%25252008.13.27.png](https://lh3.googleusercontent.com/-tGBltZbDsQw/TuWplIH9h3I/AAAAAAAAAww/rEdW5aqVj9E/s1600/Bildschirmfoto%2525202011-12-12%252520um%25252008.13.27.png)
> 
> I thought es could bring the data for this filters with its facet search.
> 
> Greetings
> 
> maik

---

<div class="post-metadata">

**Author:** ![Rauan\_Maemirov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rauan_maemirov/32/826_2.png) [@Rauan\_Maemirov](https://discuss.elastic.co/u/Rauan_Maemirov)\
**Post date:** [June 1, 2012, 7:06am UTC](https://discuss.elastic.co/t/facet-search-property-property-value/6097/13 "2012-06-01T07:06:55Z")

</div>

Hi, Shay. I'm trying to implement the same scheme as topicstarter.  
I didn't understand what do you mean by 'automatically generate facets for  
all the properly names assuming they are used as field names'.  
Should I directly define mapping for every property in properties list I  
have? But what if there are dynamic? I.e. in first document the properties  
are {color: 'black', size: 'XL'}, in the second are {capacity: '2Gb',  
generation: '5'}, etc. (and there may be a lot of types of product,so  
different document types is not a desirable solution)

понедельник, 12 декабря 2011 г., 19:08:15 UTC+6 пользователь kimchy написал:

> Since we have the mapping information, we might be able to do this, i.e.  
> automatically generate facets for all the properly names assuming they are  
> used as field names. But, you can also do it yourself, you can ask for the  
> mapping, it will include all the fields names options, and build the facets  
> request based on that. (note, the properly names will need to be fields in  
> the document).

---

<div class="post-metadata">

**Author:** ![maik](https://avatars.discourse-cdn.com/v4/letter/m/7feea3/32.png) [@maik](https://discuss.elastic.co/u/maik)\
**Post date:** [June 1, 2012, 7:24am UTC](https://discuss.elastic.co/t/facet-search-property-property-value/6097/14 "2012-06-01T07:24:05Z")

</div>

To give an update on this:  
I used the "workaround" with the concatenating of the property and its  
values.  
The application has to split the facet-results and group it manually by the  
properties.

The speed is good and so we'll use most likely that way for facetting our  
properties in our application.

On Friday, December 9, 2011 12:13:43 PM UTC+1, maik wrote:

> Yes, but this only results in something like that:
> 
> facets : [  
> "capacity": 100,  
> "speed": 150  
> ]
> 
> There is no connection to the value, and this is needed.
> 
> I helped me out in a way i don't like:  
> properties : ["capacity###4 GB", "speed###32 MB/s"]
> 
> A facet on the properties field results like this:  
> facets: [  
> "capacity###4 GB" : 30,  
> "capacity###8 GB" : 20,  
> "speed###16 MB/s": 10,  
> "speed###32 MB/s" : 40  
> ]
> 
> I have to split the properties and values in the application with the  
> split-argument "###".  
> Thats not very fast.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [June 3, 2012, 9:59am UTC](https://discuss.elastic.co/t/facet-search-property-property-value/6097/15 "2012-06-03T09:59:04Z")

</div>

I meant using the get mapping API to get the list of relevant fields you  
might care about when you facet...

On Fri, Jun 1, 2012 at 9:06 AM, Rauan Maemirov [rauan1987@gmail.com](mailto:rauan1987@gmail.com) wrote:

> Hi, Shay. I'm trying to implement the same scheme as topicstarter.  
> I didn't understand what do you mean by 'automatically generate facets for  
> all the properly names assuming they are used as field names'.  
> Should I directly define mapping for every property in properties list I  
> have? But what if there are dynamic? I.e. in first document the properties  
> are {color: 'black', size: 'XL'}, in the second are {capacity: '2Gb',  
> generation: '5'}, etc. (and there may be a lot of types of product,so  
> different document types is not a desirable solution)
> 
> понедельник, 12 декабря 2011 г., 19:08:15 UTC+6 пользователь kimchy  
> написал:
> 
> > Since we have the mapping information, we might be able to do this, i.e.  
> > automatically generate facets for all the properly names assuming they are  
> > used as field names. But, you can also do it yourself, you can ask for the  
> > mapping, it will include all the fields names options, and build the facets  
> > request based on that. (note, the properly names will need to be fields in  
> > the document).

---

<div class="post-metadata">

**Author:** ![Rauan\_Maemirov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rauan_maemirov/32/826_2.png) [@Rauan\_Maemirov](https://discuss.elastic.co/u/Rauan_Maemirov)\
**Post date:** [June 5, 2012, 9:39am UTC](https://discuss.elastic.co/t/facet-search-property-property-value/6097/16 "2012-06-05T09:39:04Z")

</div>

Hey, maik.

Do you then filter values by concatenating you facet again? I.e. filtering  
properties by "capacity###4 Gb" or do you have different fields for proper  
filtering?

пятница, 1 июня 2012 г., 13:24:05 UTC+6 пользователь maik написал:

> To give an update on this:  
> I used the "workaround" with the concatenating of the property and its  
> values.  
> The application has to split the facet-results and group it manually by  
> the properties.
> 
> The speed is good and so we'll use most likely that way for facetting our  
> properties in our application.
> 
> On Friday, December 9, 2011 12:13:43 PM UTC+1, maik wrote:
> 
> > Yes, but this only results in something like that:
> > 
> > facets : [  
> > "capacity": 100,  
> > "speed": 150  
> > ]
> > 
> > There is no connection to the value, and this is needed.
> > 
> > I helped me out in a way i don't like:  
> > properties : ["capacity###4 GB", "speed###32 MB/s"]
> > 
> > A facet on the properties field results like this:  
> > facets: [  
> > "capacity###4 GB" : 30,  
> > "capacity###8 GB" : 20,  
> > "speed###16 MB/s": 10,  
> > "speed###32 MB/s" : 40  
> > ]
> > 
> > I have to split the properties and values in the application with the  
> > split-argument "###".  
> > Thats not very fast.

---

<div class="post-metadata">

**Author:** ![maik](https://avatars.discourse-cdn.com/v4/letter/m/7feea3/32.png) [@maik](https://discuss.elastic.co/u/maik)\
**Post date:** [June 5, 2012, 9:45am UTC](https://discuss.elastic.co/t/facet-search-property-property-value/6097/17 "2012-06-05T09:45:58Z")

</div>

exactly.  
I knew the property and the value at runtime, so I can build the query with  
it.

---

<div class="post-metadata">

**Author:** ![Rauan\_Maemirov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rauan_maemirov/32/826_2.png) [@Rauan\_Maemirov](https://discuss.elastic.co/u/Rauan_Maemirov)\
**Post date:** [June 5, 2012, 2:22pm UTC](https://discuss.elastic.co/t/facet-search-property-property-value/6097/18 "2012-06-05T14:22:50Z")

</div>

Doesn't this solve exactly the same problem? (within conditions u've  
mentioned in the topic description)  
[https://groups.google.com/group/elasticsearch/browse\_thread/thread/0fb259db7552359a](https://groups.google.com/group/elasticsearch/browse_thread/thread/0fb259db7552359a)

вторник, 5 июня 2012 г., 15:45:58 UTC+6 пользователь maik написал:

> exactly.  
> I knew the property and the value at runtime, so I can build the query  
> with it.

---

<div class="post-metadata">

**Author:** ![11112](https://avatars.discourse-cdn.com/v4/letter/1/d78d45/32.png) [@11112](https://discuss.elastic.co/u/11112)\
**Post date:** [November 1, 2012, 10:40am UTC](https://discuss.elastic.co/t/facet-search-property-property-value/6097/19 "2012-11-01T10:40:18Z")

</div>

Hi kimchy!

We currently have more than 2000 (and counting) properties in our db. Is  
this ok to add all of them to mapping?

On Sunday, June 3, 2012 1:59:04 PM UTC+4, kimchy wrote:

> I meant using the get mapping API to get the list of relevant fields you  
> might care about when you facet...
> 
> On Fri, Jun 1, 2012 at 9:06 AM, Rauan Maemirov \<[raua...@gmail.com](mailto:raua...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi, Shay. I'm trying to implement the same scheme as topicstarter.  
> > I didn't understand what do you mean by 'automatically generate facets  
> > for all the properly names assuming they are used as field names'.  
> > Should I directly define mapping for every property in properties list I  
> > have? But what if there are dynamic? I.e. in first document the properties  
> > are {color: 'black', size: 'XL'}, in the second are {capacity: '2Gb',  
> > generation: '5'}, etc. (and there may be a lot of types of product,so  
> > different document types is not a desirable solution)
> > 
> > понедельник, 12 декабря 2011 г., 19:08:15 UTC+6 пользователь kimchy  
> > написал:
> > 
> > > Since we have the mapping information, we might be able to do this, i.e.  
> > > automatically generate facets for all the properly names assuming they are  
> > > used as field names. But, you can also do it yourself, you can ask for the  
> > > mapping, it will include all the fields names options, and build the facets  
> > > request based on that. (note, the properly names will need to be fields in  
> > > the document).

--

---

<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, 3:06am UTC](https://discuss.elastic.co/t/facet-search-property-property-value/6097/20 "2017-07-06T03:06:36Z")

</div>


