Aggregated field search


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:
“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


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");
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.

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).

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 :!topic/elasticsearch/Ink_LUrPy6o