Add support for compound queries

This commit adds support for the compound queries "bool", "boosting",
"constant_score" and "dis_max". The "function_score" query is not
supported yet.

Compound queries are simple. They act just like simple queries, except
that they are recursive, wrapping other simple/compound queries.

For example:

    esquery.Bool().
        Must(Term("user", "kimchy"), Term("author", "kimchy")).
        Filter(Term("tag", "tech"))
This commit is contained in:
Ido Perlmuter
2020-02-20 11:50:11 +02:00
parent 9ef149ec94
commit 6c8e71c188
8 changed files with 248 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
package esquery
import (
"testing"
)
func TestBoost(t *testing.T) {
runTests(t, []queryTest{
{
"boosting query",
Boosting().
Positive(Term("text", "apple")).
Negative(Term("text", "pie tart")).
NegativeBoost(0.5),
"{\"boosting\":{\"positive\":{\"term\":{\"text\":{\"value\":\"apple\"}}},\"negative\":{\"term\":{\"text\":{\"value\":\"pie tart\"}}},\"negative_boost\":0.5}}\n",
},
})
}