Trying to boost a result in a filtered query

I am trying to run following query. I want to boost the record if its name
contains a word pizza. Is there anything wrong in my query?. All the
records (53) returned by filter contain the word "Houston" in field
addrtext. Now I want to boost those records which contain the word pizza in
field name. I have been trying for few days with different queries but no
luck yet.
What am I missing?

{
"size" : 100,
"query" : {
"filtered" : {
"query" : {
"query_string" : {
"query" : "pizza",
"default_field" : "name^10"
}
}
},
"filter" : {
"query" : {
"query_string" : {
"query" : "Houston",
"default_field" : "addrtext"
}
}
}
}
}

Thanks for help
Ravi

--
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.

Hi,
what you are currently doing with your filtered query is 1) filtering out
all the documents that don't match the addrtext:Houston query 2) executing
the query on top of those documents.

The fact that you give a boost to the name field doesn't make any
difference since that's the only field you are searching on. The fields
weight makes sense only when searching on multiple fields, or eventually if
you have multiple queries in OR (e.g. using a bool query with should
clauses).

Cheers
Luca

On Wednesday, October 9, 2013 10:16:29 PM UTC+2, ravi...@gmail.com wrote:

I am trying to run following query. I want to boost the record if its name
contains a word pizza. Is there anything wrong in my query?. All the
records (53) returned by filter contain the word "Houston" in field
addrtext. Now I want to boost those records which contain the word pizza in
field name. I have been trying for few days with different queries but no
luck yet.
What am I missing?

{
"size" : 100,
"query" : {
"filtered" : {
"query" : {
"query_string" : {
"query" : "pizza",
"default_field" : "name^10"
}
}
},
"filter" : {
"query" : {
"query_string" : {
"query" : "Houston",
"default_field" : "addrtext"
}
}
}
}
}

Thanks for help
Ravi

--
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.

That is exactly what is happening. The filter is behaving correctly. It is
returning results containing "Houston".
The query has no effect at all.

So how do I fix this?
Basically what I want is this.
I have a set of AND filters that return me say 53 results.
Now let us say 3 of these records contain a word pizza in another field.
I want to modify the query or filter so that I get the same 53 results with
3 records containing pizza on top.
How can I do this?

Ravi

On Thursday, October 10, 2013 8:33:45 AM UTC-4, Luca Cavanna wrote:

Hi,
what you are currently doing with your filtered query is 1) filtering out
all the documents that don't match the addrtext:Houston query 2) executing
the query on top of those documents.

The fact that you give a boost to the name field doesn't make any
difference since that's the only field you are searching on. The fields
weight makes sense only when searching on multiple fields, or eventually if
you have multiple queries in OR (e.g. using a bool query with should
clauses).

Cheers
Luca

On Wednesday, October 9, 2013 10:16:29 PM UTC+2, ravi...@gmail.com wrote:

I am trying to run following query. I want to boost the record if its
name contains a word pizza. Is there anything wrong in my query?. All the
records (53) returned by filter contain the word "Houston" in field
addrtext. Now I want to boost those records which contain the word pizza in
field name. I have been trying for few days with different queries but no
luck yet.
What am I missing?

{
"size" : 100,
"query" : {
"filtered" : {
"query" : {
"query_string" : {
"query" : "pizza",
"default_field" : "name^10"
}
}
},
"filter" : {
"query" : {
"query_string" : {
"query" : "Houston",
"default_field" : "addrtext"
}
}
}
}
}

Thanks for help
Ravi

--
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.

Hi,
all documents you get back match both the filter and the query. You might
want to add the explain=true parameter to your request to know more about
what is going on under the hood.

I think I got what you want to achieve though. I would go with a bool query
that has a match_all as must clause and your query as should clause, so
that it's not mandatory but if it does match thoase documents will be
boosted. I would also replace the query_string with the match query.

{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{"match_all": {}}
],
"should": [
{
"match": {
"name": "pizza"
}
}
]
}
},
"filter": {
}
}
}
}

On Fri, Oct 11, 2013 at 3:22 AM, ravi3100@gmail.com wrote:

That is exactly what is happening. The filter is behaving correctly. It is
returning results containing "Houston".
The query has no effect at all.

So how do I fix this?
Basically what I want is this.
I have a set of AND filters that return me say 53 results.
Now let us say 3 of these records contain a word pizza in another field.
I want to modify the query or filter so that I get the same 53 results
with 3 records containing pizza on top.
How can I do this?

Ravi

On Thursday, October 10, 2013 8:33:45 AM UTC-4, Luca Cavanna wrote:

Hi,
what you are currently doing with your filtered query is 1) filtering out
all the documents that don't match the addrtext:Houston query 2) executing
the query on top of those documents.

The fact that you give a boost to the name field doesn't make any
difference since that's the only field you are searching on. The fields
weight makes sense only when searching on multiple fields, or eventually if
you have multiple queries in OR (e.g. using a bool query with should
clauses).

Cheers
Luca

On Wednesday, October 9, 2013 10:16:29 PM UTC+2, ravi...@gmail.com wrote:

I am trying to run following query. I want to boost the record if its
name contains a word pizza. Is there anything wrong in my query?. All the
records (53) returned by filter contain the word "Houston" in field
addrtext. Now I want to boost those records which contain the word pizza in
field name. I have been trying for few days with different queries but no
luck yet.
What am I missing?

{
"size" : 100,
"query" : {
"filtered" : {
"query" : {
"query_string" : {
"query" : "pizza",
"default_field" : "name^10"
}
}
},
"filter" : {
"query" : {
"query_string" : {
"query" : "Houston",
"default_field" : "addrtext"
}
}
}
}
}

Thanks for help
Ravi

--
You received this message because you are subscribed to a topic in the
Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/elasticsearch/Lm3PjY8Y1nk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.

Thanks so much. It worked like a charm!

Ravi

On Friday, October 11, 2013 4:47:27 AM UTC-4, Luca Cavanna wrote:

Hi,
all documents you get back match both the filter and the query. You might
want to add the explain=true parameter to your request to know more about
what is going on under the hood.

I think I got what you want to achieve though. I would go with a bool
query that has a match_all as must clause and your query as should clause,
so that it's not mandatory but if it does match thoase documents will be
boosted. I would also replace the query_string with the match query.

{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{"match_all": {}}
],
"should": [
{
"match": {
"name": "pizza"
}
}
]
}
},
"filter": {
}
}
}
}

On Fri, Oct 11, 2013 at 3:22 AM, <ravi...@gmail.com <javascript:>> wrote:

That is exactly what is happening. The filter is behaving correctly. It
is returning results containing "Houston".
The query has no effect at all.

So how do I fix this?
Basically what I want is this.
I have a set of AND filters that return me say 53 results.
Now let us say 3 of these records contain a word pizza in another field.
I want to modify the query or filter so that I get the same 53 results
with 3 records containing pizza on top.
How can I do this?

Ravi

On Thursday, October 10, 2013 8:33:45 AM UTC-4, Luca Cavanna wrote:

Hi,
what you are currently doing with your filtered query is 1) filtering
out all the documents that don't match the addrtext:Houston query 2)
executing the query on top of those documents.

The fact that you give a boost to the name field doesn't make any
difference since that's the only field you are searching on. The fields
weight makes sense only when searching on multiple fields, or eventually if
you have multiple queries in OR (e.g. using a bool query with should
clauses).

Cheers
Luca

On Wednesday, October 9, 2013 10:16:29 PM UTC+2, ravi...@gmail.comwrote:

I am trying to run following query. I want to boost the record if its
name contains a word pizza. Is there anything wrong in my query?. All the
records (53) returned by filter contain the word "Houston" in field
addrtext. Now I want to boost those records which contain the word pizza in
field name. I have been trying for few days with different queries but no
luck yet.
What am I missing?

{
"size" : 100,
"query" : {
"filtered" : {
"query" : {
"query_string" : {
"query" : "pizza",
"default_field" : "name^10"
}
}
},
"filter" : {
"query" : {
"query_string" : {
"query" : "Houston",
"default_field" : "addrtext"
}
}
}
}
}

Thanks for help
Ravi

--
You received this message because you are subscribed to a topic in the
Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/elasticsearch/Lm3PjY8Y1nk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.

Declared victory too soon. Your suggestion works but there is a
complication.

I have a sort section in the end. It is sorting by distance. The distance
sorting is working correct but it is messing up with results of the query.
Ideally I would like the order of all sorted results to be maintained and
only those results matching the "should" query should get bumped up in
final list. At present it is behaving as if the query section is not
present.
Is there any way to do this?
I tried sorting by distance as well as the field but did not have the
effect.
Any suggestions?

{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{"match_all": {}}
],
"should": [
{
"match": {
"name": "pizza"
}
}
]
}
},
"filter": {
}
}
},
"sort" : [
]
}

On Friday, October 11, 2013 4:47:27 AM UTC-4, Luca Cavanna wrote:

Hi,
all documents you get back match both the filter and the query. You might
want to add the explain=true parameter to your request to know more about
what is going on under the hood.

I think I got what you want to achieve though. I would go with a bool
query that has a match_all as must clause and your query as should clause,
so that it's not mandatory but if it does match thoase documents will be
boosted. I would also replace the query_string with the match query.

{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{"match_all": {}}
],
"should": [
{
"match": {
"name": "pizza"
}
}
]
}
},
"filter": {
}
}
}
}

On Fri, Oct 11, 2013 at 3:22 AM, <ravi...@gmail.com <javascript:>> wrote:

That is exactly what is happening. The filter is behaving correctly. It
is returning results containing "Houston".
The query has no effect at all.

So how do I fix this?
Basically what I want is this.
I have a set of AND filters that return me say 53 results.
Now let us say 3 of these records contain a word pizza in another field.
I want to modify the query or filter so that I get the same 53 results
with 3 records containing pizza on top.
How can I do this?

Ravi

On Thursday, October 10, 2013 8:33:45 AM UTC-4, Luca Cavanna wrote:

Hi,
what you are currently doing with your filtered query is 1) filtering
out all the documents that don't match the addrtext:Houston query 2)
executing the query on top of those documents.

The fact that you give a boost to the name field doesn't make any
difference since that's the only field you are searching on. The fields
weight makes sense only when searching on multiple fields, or eventually if
you have multiple queries in OR (e.g. using a bool query with should
clauses).

Cheers
Luca

On Wednesday, October 9, 2013 10:16:29 PM UTC+2, ravi...@gmail.comwrote:

I am trying to run following query. I want to boost the record if its
name contains a word pizza. Is there anything wrong in my query?. All the
records (53) returned by filter contain the word "Houston" in field
addrtext. Now I want to boost those records which contain the word pizza in
field name. I have been trying for few days with different queries but no
luck yet.
What am I missing?

{
"size" : 100,
"query" : {
"filtered" : {
"query" : {
"query_string" : {
"query" : "pizza",
"default_field" : "name^10"
}
}
},
"filter" : {
"query" : {
"query_string" : {
"query" : "Houston",
"default_field" : "addrtext"
}
}
}
}
}

Thanks for help
Ravi

--
You received this message because you are subscribed to a topic in the
Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/elasticsearch/Lm3PjY8Y1nk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.

Found the answer. I had to use two step sorting. First sort by _score and
then by distance.

Ravi

--
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.