# Searching key names as well

**URL:** <https://discuss.elastic.co/t/searching-key-names-as-well/7519>\
**Category:** Elasticsearch\
**Created:** [May 1, 2012, 3:53am UTC](https://discuss.elastic.co/t/searching-key-names-as-well/7519 "2012-05-01T03:53:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bcoder](https://avatars.discourse-cdn.com/v4/letter/b/3e96dc/32.png) [@bcoder](https://discuss.elastic.co/u/bcoder)\
**Post date:** [May 1, 2012, 3:53am UTC](https://discuss.elastic.co/t/searching-key-names-as-well/7519/1 "2012-05-01T03:53:40Z")

</div>

I have documents of following form indexed in ES:

{  
"foo1":  
{  
"blah1": "hello1",  
"blah2": "hello2"  
}  
}

I want to be able to search a prefix, inside "foo1" hash (both key  
names and values should be searched). So for example if I search  
"blah1", then it should be a valid match (in the example above: since  
a key with "blah1" exist). Similarly "hello1" is also a valid match  
(key value).

Is there a way to do that ?

I know that I can search something like this: {"query": {"prefix":  
{"foo1.blah1": "hello1"}}}, but this does not: 1) search entire "foo1"  
hash, 2) Search only key value of specified key (foo1.blah1 in this  
case), and not the strings representing key names.

I want to be able to say something like: Find me all documents which  
have some "text" inside the hash "foo1" (irrespective of the fact,  
wheter the text matches a key name or key value).

Note: The keys inside "foo1" hash are arbitrary and potentially  
different for each hash (both the actual name of keys and also number  
of them)

Thanks in advance!

---

<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:** [May 2, 2012, 4:23pm UTC](https://discuss.elastic.co/t/searching-key-names-as-well/7519/2 "2012-05-02T16:23:59Z")

</div>

There isn't a way to do it unless you explicitly search on all the fields.  
There has been some discussions on automatically building a compound query  
based on a wildcarded name, something like foo.\*, but it hasn't move  
further than the discussion.

On Tue, May 1, 2012 at 6:53 AM, bcoder [blitzkriegcoder@gmail.com](mailto:blitzkriegcoder@gmail.com) wrote:

> I have documents of following form indexed in ES:
> 
> {  
> "foo1":  
> {  
> "blah1": "hello1",  
> "blah2": "hello2"  
> }  
> }
> 
> I want to be able to search a prefix, inside "foo1" hash (both key  
> names and values should be searched). So for example if I search  
> "blah1", then it should be a valid match (in the example above: since  
> a key with "blah1" exist). Similarly "hello1" is also a valid match  
> (key value).
> 
> Is there a way to do that ?
> 
> I know that I can search something like this: {"query": {"prefix":  
> {"foo1.blah1": "hello1"}}}, but this does not: 1) search entire "foo1"  
> hash, 2) Search only key value of specified key (foo1.blah1 in this  
> case), and not the strings representing key names.
> 
> I want to be able to say something like: Find me all documents which  
> have some "text" inside the hash "foo1" (irrespective of the fact,  
> wheter the text matches a key name or key value).
> 
> Note: The keys inside "foo1" hash are arbitrary and potentially  
> different for each hash (both the actual name of keys and also number  
> of them)
> 
> Thanks in advance!

---

<div class="post-metadata">

**Author:** ![bcoder](https://avatars.discourse-cdn.com/v4/letter/b/3e96dc/32.png) [@bcoder](https://discuss.elastic.co/u/bcoder)\
**Post date:** [May 4, 2012, 6:13pm UTC](https://discuss.elastic.co/t/searching-key-names-as-well/7519/3 "2012-05-04T18:13:51Z")

</div>

Thanks for the swift reply! 🙂

On May 2, 9:23 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> There isn't a way to do it unless you explicitly search on all the fields.  
> There has been some discussions on automatically building a compound query  
> based on a wildcarded name, something like foo.\*, but it hasn't move  
> further than the discussion.
> 
> On Tue, May 1, 2012 at 6:53 AM, bcoder [blitzkriegco...@gmail.com](mailto:blitzkriegco...@gmail.com) wrote:
> 
> > I have documents of following form indexed in ES:
> 
> > {  
> > "foo1":  
> > {  
> > "blah1": "hello1",  
> > "blah2": "hello2"  
> > }  
> > }
> 
> > I want to be able to search a prefix, inside "foo1" hash (both key  
> > names and values should be searched). So for example if I search  
> > "blah1", then it should be a valid match (in the example above: since  
> > a key with "blah1" exist). Similarly "hello1" is also a valid match  
> > (key value).
> 
> > Is there a way to do that ?
> 
> > I know that I can search something like this: {"query": {"prefix":  
> > {"foo1.blah1": "hello1"}}}, but this does not: 1) search entire "foo1"  
> > hash, 2) Search only key value of specified key (foo1.blah1 in this  
> > case), and not the strings representing key names.
> 
> > I want to be able to say something like: Find me all documents which  
> > have some "text" inside the hash "foo1" (irrespective of the fact,  
> > wheter the text matches a key name or key value).
> 
> > Note: The keys inside "foo1" hash are arbitrary and potentially  
> > different for each hash (both the actual name of keys and also number  
> > of them)
> 
> > Thanks in advance!

---

<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:30am UTC](https://discuss.elastic.co/t/searching-key-names-as-well/7519/4 "2017-07-06T03:30:01Z")

</div>


