# Searching a specific field with a Hash value

**URL:** <https://discuss.elastic.co/t/searching-a-specific-field-with-a-hash-value/4923>\
**Category:** Elasticsearch\
**Created:** [July 22, 2011, 4:17am UTC](https://discuss.elastic.co/t/searching-a-specific-field-with-a-hash-value/4923 "2011-07-22T04:17:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kikster](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kikster/32/3117_2.png) [@kikster](https://discuss.elastic.co/u/kikster)\
**Post date:** [July 22, 2011, 4:17am UTC](https://discuss.elastic.co/t/searching-a-specific-field-with-a-hash-value/4923/1 "2011-07-22T04:17:40Z")

</div>

I have a document under a type called "user". The user has different  
attributes like this:

{  
"id" : 3,  
"location" : "New York",  
"about\_me" : "I like to surf, snowboard, and watch the Giants play.",  
"interests" : {"extreme\_sports" : "snowboard", "movies" : "inception"}  
}

I want to search the user for data matching "snowboard", but only want to  
look in the "interests" field. I've tried the following query:  
{  
"query" : {  
"term" : {  
"interests" : "snowboard"  
}  
}  
}

I tried to restrict the search for the string "snowboard" to only the  
"interests" field, however this returns no hits. I'm assuming it's because  
the "interests" field contains a hash, not a simple string. How do I tell  
elasticsearch to search for values within the "interests" field when it  
contains a hash?

--  
View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Searching-a-specific-field-with-a-Hash-value-tp3190358p3190358.html](http://elasticsearch-users.115913.n3.nabble.com/Searching-a-specific-field-with-a-Hash-value-tp3190358p3190358.html)  
Sent from the ElasticSearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<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:** [July 24, 2011, 2:47am UTC](https://discuss.elastic.co/t/searching-a-specific-field-with-a-hash-value/4923/2 "2011-07-24T02:47:04Z")

</div>

Yes, its because it contains a "hash", the fields indexed are actually  
interests.extreme\_sports, .. . So, you need to query on those. That said, I  
think that in certain queries, we can support automatically expanding  
something like interests field (which maps to an object mapping) to all its  
sub fields.

On Fri, Jul 22, 2011 at 7:17 AM, cdolive \<[christopherdavidolivares@gmail.com](mailto:christopherdavidolivares@gmail.com)

> wrote:

> I have a document under a type called "user". The user has different  
> attributes like this:
> 
> {  
> "id" : 3,  
> "location" : "New York",  
> "about\_me" : "I like to surf, snowboard, and watch the Giants play.",  
> "interests" : {"extreme\_sports" : "snowboard", "movies" : "inception"}  
> }
> 
> I want to search the user for data matching "snowboard", but only want to  
> look in the "interests" field. I've tried the following query:  
> {  
> "query" : {  
> "term" : {  
> "interests" : "snowboard"  
> }  
> }  
> }
> 
> I tried to restrict the search for the string "snowboard" to only the  
> "interests" field, however this returns no hits. I'm assuming it's because  
> the "interests" field contains a hash, not a simple string. How do I tell  
> elasticsearch to search for values within the "interests" field when it  
> contains a hash?
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Searching-a-specific-field-with-a-Hash-value-tp3190358p3190358.html](http://elasticsearch-users.115913.n3.nabble.com/Searching-a-specific-field-with-a-Hash-value-tp3190358p3190358.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![kikster](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kikster/32/3117_2.png) [@kikster](https://discuss.elastic.co/u/kikster)\
**Post date:** [July 25, 2011, 7:03pm UTC](https://discuss.elastic.co/t/searching-a-specific-field-with-a-hash-value/4923/3 "2011-07-25T19:03:01Z")

</div>

Thanks Shay! Is there anywhere I can look to see which queries automatically expand and search on every hash value?

---

<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:** [July 27, 2011, 4:39am UTC](https://discuss.elastic.co/t/searching-a-specific-field-with-a-hash-value/4923/4 "2011-07-27T04:39:28Z")

</div>

I said we can look into supporting that, there is no support for it  
currently.

On Mon, Jul 25, 2011 at 10:03 PM, Kikster \<  
[christopherdavidolivares@gmail.com](mailto:christopherdavidolivares@gmail.com)\> wrote:

> Thanks Shay! Is there anywhere I can look to see which queries  
> automatically  
> expand and search on every hash value?
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Searching-a-specific-field-with-a-Hash-value-tp3193609p3198370.html](http://elasticsearch-users.115913.n3.nabble.com/Searching-a-specific-field-with-a-Hash-value-tp3193609p3198370.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<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:59am UTC](https://discuss.elastic.co/t/searching-a-specific-field-with-a-hash-value/4923/5 "2017-07-06T03:59:08Z")

</div>


