# ElasticSearch for Attribute(Key) value data set

**URL:** <https://discuss.elastic.co/t/elasticsearch-for-attribute-key-value-data-set/13250>\
**Category:** Elasticsearch\
**Created:** [August 19, 2013, 5:24am UTC](https://discuss.elastic.co/t/elasticsearch-for-attribute-key-value-data-set/13250 "2013-08-19T05:24:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mahdi\_Mazaheri](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@Mahdi\_Mazaheri](https://discuss.elastic.co/u/Mahdi_Mazaheri)\
**Post date:** [August 19, 2013, 5:24am UTC](https://discuss.elastic.co/t/elasticsearch-for-attribute-key-value-data-set/13250/1 "2013-08-19T05:24:46Z")

</div>

0down votefavorite[http://stackoverflow.com/questions/18306833/elasticsearch-for-attributekey-value-data-set#](http://stackoverflow.com/questions/18306833/elasticsearch-for-attributekey-value-data-set#)  
\*\*

I am using Elasticsearch with Haystacksearch and Django and want to search  
the follow structure:

{  
{  
"title": "book1",  
"category" : ["Cat\_1", "Cat\_2"],  
"key\_values" :  
[  
{  
"key\_name" : "key\_1",  
"value" : "sample\_value\_1"  
},  
{  
"key\_name" : "key\_2",  
"value" : "sample\_value\_12"  
}  
]  
},

```
{
    "title": "book2",
    "category" : ["Cat_3", "Cat_2"],
    "key_values" :
    [
        {
            "key_name" : "key_1",
            "value" : "sample_value_1"
        },
        {
            "key_name" : "key_3",
            "value" : "sample_value_6"
        },
        {
            "key_name" : "key_4",
            "value" : "sample_value_5"
        }
    ]
}

```

}

Right now I have set up an index model using Haystack with a "text" that  
put all the data together and runs a full text search! In my opinion this  
is not the a well established search 'cause I am not using my data set  
structure and hence this is some kind odd.  
As an example if for an object i have a key-value "{"key\_name" :  
"key\_1","value" : "sample\_value\_1"}" and for another object I have  
"{"key\_name" : "key\_2","value" : "sample\_value\_1"}" and we it gets a query  
like "Key\_1 sample\_value\_1" comes I get a thoroughly mixed result of  
objects who have these words in their fields rather than using their  
structures.

P.S. I am totally new to ElasticSearch and better to say new to the search  
technologies and challenges. I have searched the web and SO button didn't  
find anything satisfying. Please let me know if there is something wrong  
with my thoughts and expectations from these search engines and if there is  
SO duplicate question! And also if there is a better approach to design a  
database for this kind of search

Thanks in advance!

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [August 19, 2013, 8:07pm UTC](https://discuss.elastic.co/t/elasticsearch-for-attribute-key-value-data-set/13250/2 "2013-08-19T20:07:58Z")

</div>

If I understand your problem correctly, what you is probably occurring is  
that you are searching the \_all field:

> **[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.

Can you provide your mapping and an example query? By default, all fields  
get aggregated into the \_all field, and query\_string queries with no stated  
fields will use this field.

Also, nested objects might be better for your use case:

> **[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.

With nested objects, you can run a multi-field query and only match on  
nested object that satisfy all the conditions.

Cheers,

Ivan

On Sun, Aug 18, 2013 at 10:24 PM, Mahdi Mazaheri [me.mazaheri@gmail.com](mailto:me.mazaheri@gmail.com)wrote:

> 0down votefavorite[http://stackoverflow.com/questions/18306833/elasticsearch-for-attributekey-value-data-set#](http://stackoverflow.com/questions/18306833/elasticsearch-for-attributekey-value-data-set#)  
> \*\*
> 
> I am using Elasticsearch with Haystacksearch and Django and want to search  
> the follow structure:
> 
> {  
> {  
> "title": "book1",  
> "category" : ["Cat\_1", "Cat\_2"],  
> "key\_values" :  
> [  
> {  
> "key\_name" : "key\_1",  
> "value" : "sample\_value\_1"  
> },  
> {  
> "key\_name" : "key\_2",  
> "value" : "sample\_value\_12"  
> }  
> ]  
> },
> 
> ```
> {
> "title": "book2",
> "category" : ["Cat_3", "Cat_2"],
> "key_values" :
> [
> {
> "key_name" : "key_1",
> "value" : "sample_value_1"
> },
> {
> "key_name" : "key_3",
> "value" : "sample_value_6"
> },
> {
> "key_name" : "key_4",
> "value" : "sample_value_5"
> }
> ]
> }
> 
> ```
> 
> }
> 
> Right now I have set up an index model using Haystack with a "text" that  
> put all the data together and runs a full text search! In my opinion this  
> is not the a well established search 'cause I am not using my data set  
> structure and hence this is some kind odd.  
> As an example if for an object i have a key-value "{"key\_name" :  
> "key\_1","value" : "sample\_value\_1"}" and for another object I have  
> "{"key\_name" : "key\_2","value" : "sample\_value\_1"}" and we it gets a query  
> like "Key\_1 sample\_value\_1" comes I get a thoroughly mixed result of  
> objects who have these words in their fields rather than using their  
> structures.
> 
> P.S. I am totally new to Elasticsearch and better to say new to the search  
> technologies and challenges. I have searched the web and SO button didn't  
> find anything satisfying. Please let me know if there is something wrong  
> with my thoughts and expectations from these search engines and if there is  
> SO duplicate question! And also if there is a better approach to design a  
> database for this kind of search
> 
> Thanks in advance!
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:20am UTC](https://discuss.elastic.co/t/elasticsearch-for-attribute-key-value-data-set/13250/3 "2017-07-06T02:20:37Z")

</div>


