Index-wide search for N documents per type


(Ville Mattila) #1

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.

Best regards,
Ville

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/38e263ec-3a24-48c0-bd7e-20b7264418d5%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Binh Ly) #2

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

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-multi-search.html

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.

Best regards,
Ville

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/07e47c29-c526-413e-8042-d4f2a1861ca1%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Ville Mattila) #3

Hi,

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: http://stackoverflow.com/a/17532062/769144) 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):

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-multi-search.html

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.

Best regards,
Ville

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/71cda819-2677-4c7f-aedb-1a9433c1e2ea%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Binh Ly) #4

Ville,

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:

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/fff25157-0df8-407b-939c-5fe65775d60d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(system) #5