Prioritize document


(Zsolt) #1

Hi,

I have the following 3 documents:

{
"product" : "D1",
"owner" : "global"
},
{
"product" : "D1",
"owner" : "john"
},
{
"product" : "D2",
"owner" : "global"
}

There is always a "product" with "owner": "global" and only sometimes the
same product with different owner (basically a product is customized for a
user). I would like to return all products but only the customized version
for a product where it exists (where "owner" = "a-user-name"). So for the
my example I would like returned the following two docs:

{
"product" : "D1",
"owner" : "john"
},
{
"product" : "D2",
"owner" : "global"
}

I would appreciate some help on how I could solve this.

Thanks

--
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/1298ddd6-3cad-4219-89cd-67c5f2642c78%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Zsolt) #2

Nobody?

--
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/4749653c-5af2-4505-a502-39934d418566%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Mark Harwood) #3

I would like to return all products but only the customized version for a
product where it exists (where "owner" = "a-user-name").

Search for:
user-name:(global OR john)
Combine this with a terms aggregation to break down by "product" field and
below that nest a "top_hits" aggregation with a size of 1.

The search should naturally rank a match on a user name higher than a match
on "global" (assuming global is very common and per-user customizations are
rare).
Otherwise look into boosts.
The top_hits agg should then select the best-scoring option for each
product.

Obviously if you have millions of products this could present a memory
issue.

Cheers
Mark

--
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/dead03ff-3f0f-4217-b8de-2cde93ab4fdb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(deepak_daffodil) #4

i think , query string query may be useful with applying operator

On Wed, Apr 29, 2015 at 1:54 PM, mark@elastic.co wrote:

I would like to return all products but only the customized version for a
product where it exists (where "owner" = "a-user-name").

Search for:
user-name:(global OR john)
Combine this with a terms aggregation to break down by "product" field and
below that nest a "top_hits" aggregation with a size of 1.

The search should naturally rank a match on a user name higher than a
match on "global" (assuming global is very common and per-user
customizations are rare).
Otherwise look into boosts.
The top_hits agg should then select the best-scoring option for each
product.

Obviously if you have millions of products this could present a memory
issue.

Cheers
Mark

--
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/dead03ff-3f0f-4217-b8de-2cde93ab4fdb%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/dead03ff-3f0f-4217-b8de-2cde93ab4fdb%40googlegroups.com?utm_medium=email&utm_source=footer
.

For more options, visit https://groups.google.com/d/optout.

--
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/CAHzCMpoHyHj9EdARDDzBFGy_aa%3DwYSmXmut1GevqgvBA4y9uQA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(Zsolt) #5

Thanks Mark, this returns the desired results.

Unfortunately it seems to have introduced a new issue. I don't have
millions of products but enough so I use paging and as I can see, it is not
possible to page/sort the returned buckets (issue 4915
https://github.com/elastic/elasticsearch/issues/4915)...

\Zsolt

On Wednesday, 29 April 2015 10:24:04 UTC+2, ma...@elastic.co wrote:

I would like to return all products but only the customized version for a
product where it exists (where "owner" = "a-user-name").

Search for:
user-name:(global OR john)
Combine this with a terms aggregation to break down by "product" field and
below that nest a "top_hits" aggregation with a size of 1.

The search should naturally rank a match on a user name higher than a
match on "global" (assuming global is very common and per-user
customizations are rare).
Otherwise look into boosts.
The top_hits agg should then select the best-scoring option for each
product.

Obviously if you have millions of products this could present a memory
issue.

Cheers
Mark

--
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/fb71b53b-11d0-466a-ac4f-9bf2ec1c7194%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Mark Harwood) #6

You could break the products into an arbitrary number of batches as follows
(in this case page 5 of 100):

{
"aggs":{
"productsPage":{
"terms":{

"script":"p=doc['product'].value;if(p.hashCode()%100==5)return p;return
null;"
}
}
}
}

On Wednesday, April 29, 2015 at 12:34:13 PM UTC+1, Zsolt wrote:

Thanks Mark, this returns the desired results.

Unfortunately it seems to have introduced a new issue. I don't have
millions of products but enough so I use paging and as I can see, it is not
possible to page/sort the returned buckets (issue 4915
https://github.com/elastic/elasticsearch/issues/4915)...

\Zsolt

On Wednesday, 29 April 2015 10:24:04 UTC+2, ma...@elastic.co wrote:

I would like to return all products but only the customized version for
a product where it exists (where "owner" = "a-user-name").

Search for:
user-name:(global OR john)
Combine this with a terms aggregation to break down by "product" field
and below that nest a "top_hits" aggregation with a size of 1.

The search should naturally rank a match on a user name higher than a
match on "global" (assuming global is very common and per-user
customizations are rare).
Otherwise look into boosts.
The top_hits agg should then select the best-scoring option for each
product.

Obviously if you have millions of products this could present a memory
issue.

Cheers
Mark

--
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/a995a89d-fab0-49f7-a378-5f13a3554a10%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Zsolt) #7

Is there a way of getting the total results without actually returning and
counting the elements of the bucket array?

On Wednesday, 29 April 2015 13:49:57 UTC+2, ma...@elastic.co wrote:

You could break the products into an arbitrary number of batches as
follows (in this case page 5 of 100):

{
"aggs":{
"productsPage":{
"terms":{

"script":"p=doc['product'].value;if(p.hashCode()%100==5)return p;return
null;"
}
}
}
}

--
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/e842a236-1b49-4db7-ac17-72dce7517771%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #8