Using result of one query in another query


Is the following query possible with elastic search:

I have two types: company and category

  • Company is a type containing fields like name, phone, keywords, location…
    and also a special field called category-id which contains an id (number)

company {
keywords: yellow pages, white pages

category-id: 1234

  • Category is a type containing an id (the category id mentioned above) and
    a set of names for that category

category {
names: software, applications

Now I want to do a query: give me all companies where the category is
software and it should return the list of companies in this category (so it
would include Truvo). ~ a join in sql

Of course I can merge the two types before indexing, but keeping it in two
separate types provides me the flexibility to update the listings (for
example adding a synonym computer programs to the category 1234) without the
need to reindex the companies.

I could of course do this also by doing two queries (the first one to
retrieve the categories, because it could be more than one category) and
then doing a second query using the result of the first query, but I would
like (id possible) to do this in one query.

Any suggestions?


View this message in context:
Sent from the ElasticSearch Users mailing list archive at