I have an index of approximately 10 different document types. When user
does a search, I'd like to provide a couple (let's say 5) of hits of each
type for the user to narrow the search to some type only. At this point, I
should also provide a total number of hits per type. Currently I make 10
searches against the index with total result count of 5, but was wondering
whether similar results could be received with only one search against ES?
I'd like to also use ES's scoring capabilities to get the index-wide best
match (no matter which type) as the preferred type, apparently no when the
queries are done per-type the scores are also given per type and they are
not comparable with each other.
I'm not sure if you know or have tried this, but there is a multi-search
API that allows you to make 1 call to contain multiple search queries (each
search query can refer to a type, or an index if needed):
I know it's still not a single query but at least you can get all the
results back in 1 shot and then manipulate them in 1 shot before you return
the results to your user.
On Friday, January 24, 2014 5:57:26 AM UTC-5, Ville Mattila wrote:
Hi,
I have an index of approximately 10 different document types. When user
does a search, I'd like to provide a couple (let's say 5) of hits of each
type for the user to narrow the search to some type only. At this point, I
should also provide a total number of hits per type. Currently I make 10
searches against the index with total result count of 5, but was wondering
whether similar results could be received with only one search against ES?
I'd like to also use ES's scoring capabilities to get the index-wide best
match (no matter which type) as the preferred type, apparently no when the
queries are done per-type the scores are also given per type and they are
not comparable with each other.
Thanks for your reply, I think this is at least better than doing 10
separate queries. As far as I understood, the queries themselves are still
executed separately by ES, so the result scoring is done also
independently, isn't it? To be honest, I am not sure if it matters here
largerly... I think I need to learn the scoring mechanism (found good links
from this SO answer: search - ElasticSearch default scoring mechanism - Stack Overflow) a bit more.
Thanks!
Ville
Ville:
I'm not sure if you know or have tried this, but there is a multi-search
API that allows you to make 1 call to contain multiple search queries (each
search query can refer to a type, or an index if needed):
I know it's still not a single query but at least you can get all the
results back in 1 shot and then manipulate them in 1 shot before you return
the results to your user.
On Friday, January 24, 2014 5:57:26 AM UTC-5, Ville Mattila wrote:
Hi,
I have an index of approximately 10 different document types. When user
does a search, I'd like to provide a couple (let's say 5) of hits of each
type for the user to narrow the search to some type only. At this point, I
should also provide a total number of hits per type. Currently I make 10
searches against the index with total result count of 5, but was wondering
whether similar results could be received with only one search against ES?
I'd like to also use ES's scoring capabilities to get the index-wide best
match (no matter which type) as the preferred type, apparently no when the
queries are done per-type the scores are also given per type and they are
not comparable with each other.
About the scoring, yeah each query you send in to the _msearch API will
have a separate result with it's own scores. You can send multiple querys,
let's say 1 query for each type, and then 1 overall query at the index
level. I don't know if that would help but it can be done through _msearch.
You can also take a look at the function_score query type to customize
scoring (at the DSL level) if it helps:
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.