Syntax for combining boosted query components


(conor) #1

Hello all.

I am testing different query options and want to try combining
different query elements together with a boosting factor. So for
example, suppose I want to use a more_like_this query for some
like_text against a field AND I would like to use a trem query against
a different field. And I would like to combine these elements such
that the term query is boosted by a factor of 2.

Assume the fields are field_a, field_b and field_c (all strings).
Assume the first query element is:- "more_like_this": {"like_text":
"text like this", fields: ["field_a", "field_b"]}
Assume the second query element is:- "term": {"field_c": {"value":
"foo", "boost": 2.0}}

And the question is, what is the right syntax to put these together in
a query?

Thanks,

Conor


(Shay Banon) #2

You can put them in a bool query should/must clauses.
On Wednesday, May 11, 2011 at 12:55 AM, Conor wrote:

Hello all.

I am testing different query options and want to try combining
different query elements together with a boosting factor. So for
example, suppose I want to use a more_like_this query for some
like_text against a field AND I would like to use a trem query against
a different field. And I would like to combine these elements such
that the term query is boosted by a factor of 2.

Assume the fields are field_a, field_b and field_c (all strings).
Assume the first query element is:- "more_like_this": {"like_text":
"text like this", fields: ["field_a", "field_b"]}
Assume the second query element is:- "term": {"field_c": {"value":
"foo", "boost": 2.0}}

And the question is, what is the right syntax to put these together in
a query?

Thanks,

Conor


(conor) #3

Thanks. It was not intuitive to me that a boolean combination of fuzzy component queries (i.e. not an underlying boolean value but a score) were the semantics, but it does the job nicely.

The test query I used is listed below.

Cheers.

C

{ "query":
{"bool" :
{ "should": [
{"mlt":
{ "like_text": "bar bar foo bing", "min_doc_freq": 1 }
},
{"term" :
{ "field_c": { "value": "baz", "boost": 4.0}}
}
]}
}
}


(system) #4