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:
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)
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.
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: query.json · GitHub
You can use the nested query's score mode to control how the scores from
the criteria objects are mapped into the search hits:
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:
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)
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.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.