Help querying array of nested objects

Hello,

I'm having difficulty crafting a query and I was hoping for some help. I
created a gist with the general idea: https://gist.github.com/rolyv/4725510

Each of my documents has an array of these "criteria" objects. These
criteria objects each have a boolean flag for requiredness and a token id.
Each user in the system has a set of tokens. So when a user executes a
query, I take the user's tokens and I want to craft a query/filter so that
the documents returned follow this logic:

  1. a document is returned if all its required criteria are met by the user.
    (a document with only optional, required = false, criteria would also be
    returned)
  2. the score of the document should directly relate to how many of the
    criteria are met by the user (both optional and required).

I think I can do part 2 straightforwardly with a bool query and a bunch of
should clauses, but the filter for part 1 is evading me. Any help is much
appreciated.

Thanks,

Roly

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hey Roly,

To query in your criteria objects you will need to use a nested
query/filter as a wrapper. For the other properties you can use a regular
query.
See my query example here: https://gist.github.com/martijnvg/4739823

You can use the nested query's score mode to control how the scores from
the criteria objects are mapped into the search hits:
http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html

Martijn

On 6 February 2013 21:41, Roly Vicaria rolyv19@gmail.com wrote:

Hello,

I'm having difficulty crafting a query and I was hoping for some help. I
created a gist with the general idea:
https://gist.github.com/rolyv/4725510

Each of my documents has an array of these "criteria" objects. These
criteria objects each have a boolean flag for requiredness and a token id.
Each user in the system has a set of tokens. So when a user executes a
query, I take the user's tokens and I want to craft a query/filter so that
the documents returned follow this logic:

  1. a document is returned if all its required criteria are met by the
    user. (a document with only optional, required = false, criteria would also
    be returned)
  2. the score of the document should directly relate to how many of the
    criteria are met by the user (both optional and required).

I think I can do part 2 straightforwardly with a bool query and a bunch of
should clauses, but the filter for part 1 is evading me. Any help is much
appreciated.

Thanks,

Roly

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
Met vriendelijke groet,

Martijn van Groningen

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.