I'm using ES 6.6 and I use Java RestClient
I try to create query like this.
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery()
.should(
QueryBuilders.multiMatchQuery...
)
.must(
QueryBuilders.disMaxQuery()
.tieBreaker(0.0f)
.add(//multi match)
.add(//multi match)
)
.filter(
QueryBuilders.functionScoreQuery(
QueryBuilders.disMaxQuery()
.tieBreaker(0.0f)
.add(//multi match)
.add(//multi match)
).setMinScore(0.5f)
)
.filter(
QueryBuilders.boolQuery().mustNot(
JoinQueryBuilders.hasParentQuery("parent",
//multi match, false)
)
);
I expected JSON like this
{
"bool" : {
"should" : [
{
"multi_match" : {
"query" : "PLACE",
"fields" : [
"anames.*^25.0"
],
"type" : "cross_fields",
"operator" : "OR",
"slop" : 0,
"prefix_length" : 0,
"max_expansions" : 50,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : false,
"fuzzy_transpositions" : false,
"boost" : 1.0
}
}
],
"must" : [
{
"dis_max" : {
"tie_breaker" : 0.0,
"queries" : [
{
"multi_match" : {
"query" : "TARGET",
"fields" : [
"anames.analyze*^5.0",
"class_name*^25.0",
"fname.analyze*^5.0"
],
"type" : "best_fields",
"operator" : "AND",
"slop" : 0,
"prefix_length" : 0,
"max_expansions" : 50,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : false,
"fuzzy_transpositions" : false,
"boost" : 1.0
}
},
{
"nested" : {
"query" : {
"multi_match" : {
"query" : "TARGET",
"fields" : [
"aliases.alias*^10.0"
],
"type" : "best_fields",
"operator" : "AND",
"slop" : 0,
"prefix_length" : 0,
"max_expansions" : 50,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : false,
"fuzzy_transpositions" : false,
"boost" : 1.0
}
},
"path" : "aliases",
"ignore_unmapped" : false,
"score_mode" : "max",
"boost" : 1.0
}
}
],
"boost" : 1.0
}
}
],
"filter" : [
{
"function_score" : {
"query" : {
"dis_max" : {
"tie_breaker" : 0.0,
"queries" : [
{
"multi_match" : {
"query" : "TARGET",
"fields" : [
"anames.analyze^1.0"
],
"type" : "best_fields",
"operator" : "OR",
"slop" : 0,
"prefix_length" : 0,
"max_expansions" : 50,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : false,
"fuzzy_transpositions" : false,
"boost" : 1.0
}
},
{
"nested" : {
"query" : {
"multi_match" : {
"query" : "TARGET",
"fields" : [
"aliases.alias.analyze^1.0"
],
"type" : "best_fields",
"operator" : "AND",
"slop" : 0,
"prefix_length" : 0,
"max_expansions" : 50,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : false,
"fuzzy_transpositions" : false,
"boost" : 1.0
}
},
"path" : "aliases",
"ignore_unmapped" : false,
"score_mode" : "max",
"boost" : 1.0
}
}
],
"boost" : 1.0
}
},
"functions" : [ ],
"score_mode" : "multiply",
"max_boost" : 3.4028235E38,
"min_score" : 0.5,
"boost" : 1.0
}
},
{
"bool" : {
"must_not" : [
{
"has_parent" : {
"query" : {
"multi_match" : {
"query" : "TARGET",
"fields" : [
"class_name*^1.0"
],
"type" : "best_fields",
"operator" : "AND",
"slop" : 0,
"prefix_length" : 0,
"max_expansions" : 50,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : false,
"fuzzy_transpositions" : false,
"boost" : 1.0
}
},
"parent_type" : "parent",
"score" : false,
"ignore_unmapped" : false,
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
but, actually created query is this.
{
"bool" : {
"must" : [
{
"dis_max" : {
"tie_breaker" : 0.0,
"queries" : [
{
"multi_match" : {
"query" : "TARGET",
"fields" : [
"anames.analyze*^5.0",
"class_name*^25.0",
"fname.analyze*^5.0"
],
"type" : "best_fields",
"operator" : "AND",
"slop" : 0,
"prefix_length" : 0,
"max_expansions" : 50,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : false,
"fuzzy_transpositions" : false,
"boost" : 1.0
}
},
{
"nested" : {
"query" : {
"multi_match" : {
"query" : "TARGET",
"fields" : [
"aliases.alias*^10.0"
],
"type" : "best_fields",
"operator" : "AND",
"slop" : 0,
"prefix_length" : 0,
"max_expansions" : 50,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : false,
"fuzzy_transpositions" : false,
"boost" : 1.0
}
},
"path" : "aliases",
"ignore_unmapped" : false,
"score_mode" : "max",
"boost" : 1.0
}
}
],
"boost" : 1.0
}
}
],
"filter" : [
{
"function_score" : {
"query" : {
"dis_max" : {
"tie_breaker" : 0.0,
"queries" : [
{
"multi_match" : {
"query" : "TARGET",
"fields" : [
"anames.analyze^1.0"
],
"type" : "best_fields",
"operator" : "OR",
"slop" : 0,
"prefix_length" : 0,
"max_expansions" : 50,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : false,
"fuzzy_transpositions" : false,
"boost" : 1.0
}
},
{
"nested" : {
"query" : {
"multi_match" : {
"query" : "TARGET",
"fields" : [
"aliases.alias.analyze^1.0"
],
"type" : "best_fields",
"operator" : "AND",
"slop" : 0,
"prefix_length" : 0,
"max_expansions" : 50,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : false,
"fuzzy_transpositions" : false,
"boost" : 1.0
}
},
"path" : "aliases",
"ignore_unmapped" : false,
"score_mode" : "max",
"boost" : 1.0
}
}
],
"boost" : 1.0
}
},
"functions" : [ ],
"score_mode" : "multiply",
"max_boost" : 3.4028235E38,
"min_score" : 0.5,
"boost" : 1.0
}
},
{
"bool" : {
"must_not" : [
{
"has_parent" : {
"query" : {
"multi_match" : {
"query" : "TARGET",
"fields" : [
"class_name*^1.0"
],
"type" : "best_fields",
"operator" : "AND",
"slop" : 0,
"prefix_length" : 0,
"max_expansions" : 50,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : false,
"fuzzy_transpositions" : false,
"boost" : 1.0
}
},
"parent_type" : "parent",
"score" : false,
"ignore_unmapped" : false,
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
],
"should" : [
{
"multi_match" : {
"query" : "PLACE",
"fields" : [
"anames.*^25.0"
],
"type" : "cross_fields",
"operator" : "OR",
"slop" : 0,
"prefix_length" : 0,
"max_expansions" : 50,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : false,
"fuzzy_transpositions" : false,
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
these two queries search different results.
should query goes to inside of filter.