# Aggregated field search

**URL:** <https://discuss.elastic.co/t/aggregated-field-search/6089>\
**Category:** Elasticsearch\
**Created:** [December 7, 2011, 4:38pm UTC](https://discuss.elastic.co/t/aggregated-field-search/6089 "2011-12-07T16:38:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amir\_Arad](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@Amir\_Arad](https://discuss.elastic.co/u/Amir_Arad)\
**Post date:** [December 7, 2011, 4:38pm UTC](https://discuss.elastic.co/t/aggregated-field-search/6089/1 "2011-12-07T16:38:00Z")

</div>

Hi,

I'm trying to do a search of aggregated field values.

My basic user story (I use the Java API):

Class A{  
String organization;  
… and 5 more member fields that should be indexed but are irrelevant  
for this story  
}

We have 10K entities of type A with various values indexed.

Now the user wants to search for organizations by matching the string  
“micro” to field organization (field query). He does not care about  
entities of type A, he only wants an ordered list or strings,  
representing the relevant values submitted in the organization field  
for the matched entities.

For example, he might expect as result such as:  
“Microsoft”  
“Micro – Tech”  
“Trend Micro”  
…

How do I do that with elastic search? I read the site and didn't find  
an answer.

Another story is when the user is still searching for organization  
values, but is using a field query on another field in type A.

Any hints?

Thank you

Amir.

---

<div class="post-metadata">

**Author:** ![alichi](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@alichi](https://discuss.elastic.co/u/alichi)\
**Post date:** [December 7, 2011, 8:10pm UTC](https://discuss.elastic.co/t/aggregated-field-search/6089/2 "2011-12-07T20:10:41Z")

</div>

Hi Amir,

Try this and let me if it helped:

```
    WildcardQueryBuilder wildQuery = 

```

QueryBuilders.wildcardQuery("organization", "micro\*");  
SearchRequestBuilder request =  
elasticSearchClient.prepareSearch("your index name").setTypes("your  
document type");  
request.setQuery(wildQuery);  
return request.execute().actionGet();

Disclaimer: Do not use "\*" or "?" before "micro" or it will hurt the  
performance. Also, you need to make the field "organization" analyzed (you  
can try the default standard to begin the test)

Let me know if it helped.  
Thanks,  
Ali

---

<div class="post-metadata">

**Author:** ![alichi](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@alichi](https://discuss.elastic.co/u/alichi)\
**Post date:** [December 7, 2011, 8:16pm UTC](https://discuss.elastic.co/t/aggregated-field-search/6089/3 "2011-12-07T20:16:11Z")

</div>

I forgot to add that you can manage the result to be narrowed down to only  
one field instead of the entire document. However, you still need to  
de-serialize the returned result set into proper objects (a set of strings  
or a set of objects).  
Ali

---

<div class="post-metadata">

**Author:** ![alichi](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@alichi](https://discuss.elastic.co/u/alichi)\
**Post date:** [December 7, 2011, 9:25pm UTC](https://discuss.elastic.co/t/aggregated-field-search/6089/4 "2011-12-07T21:25:28Z")

</div>

You can also take a look at this post, it is about autocomplete. I don't  
know why but I felt you had a similar issue :  
[https://groups.google.com/forum/#!topic/elasticsearch/Ink\_LUrPy6o](https://groups.google.com/forum/#!topic/elasticsearch/Ink_LUrPy6o)

---

<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:46am UTC](https://discuss.elastic.co/t/aggregated-field-search/6089/5 "2017-07-06T03:46:06Z")

</div>


