Skip to content

Commit 0edaf12

Browse files
committed
fix #477 do not render query property on function_score queries if the query is conditionless, omission is sufficient to mean match_all
1 parent 4a34eaa commit 0edaf12

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

Diff for: src/Nest/DSL/Query/FunctionScoreQueryDescriptor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public FunctionScoreQueryDescriptor<T> Query(Func<QueryDescriptor<T>, BaseQuery>
4949
var query = new QueryDescriptor<T>();
5050
var q = querySelector(query);
5151

52-
this._Query = q;
52+
this._Query = q.IsConditionless ? null : q;
5353
return this;
5454
}
5555

Diff for: src/Tests/Nest.Tests.Unit/Search/Query/Singles/FunctionScoreQueryJson.cs

+38
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,43 @@ public void FunctionScoreQuery()
4545
}";
4646
Assert.True(json.JsonEquals(expected), json);
4747
}
48+
49+
[Test]
50+
public void FunctionScoreQueryConditionless()
51+
{
52+
var s = new SearchDescriptor<ElasticsearchProject>().From(0).Size(10)
53+
.Query(q => q
54+
.FunctionScore(fs => fs
55+
.Query(qq => qq.Term("", ""))
56+
.Functions(
57+
f => f.Gauss(x => x.StartedOn, d => d.Scale("42w")),
58+
f => f.Linear(x => x.FloatValue, d => d.Scale("0.3")),
59+
f => f.Exp(x => x.DoubleValue, d => d.Scale("0.5")),
60+
f => f.BoostFactor(2)
61+
)
62+
.ScoreMode(FunctionScoreMode.sum)
63+
.BoostMode(FunctionBoostMode.replace)
64+
)
65+
).Fields(x => x.Content);
66+
67+
var json = TestElasticClient.Serialize(s);
68+
var expected = @"{
69+
from: 0, size: 10,
70+
query : {
71+
function_score : {
72+
functions: [
73+
{gauss: { startedOn : { scale: '42w'}}},
74+
{linear: { floatValue : { scale: '0.3'}}},
75+
{exp: { doubleValue: { scale: '0.5'}}},
76+
{boost_factor: 2.0 }
77+
],
78+
score_mode: 'sum',
79+
boost_mode: 'replace',
80+
}
81+
},
82+
fields: [""content""]
83+
}";
84+
Assert.True(json.JsonEquals(expected), json);
85+
}
4886
}
4987
}

0 commit comments

Comments
 (0)