Skip to content

Commit fea53ca

Browse files
committed
FunctionScoreQuery: weight should also exist at the query level
1 parent 3764183 commit fea53ca

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/Nest/DSL/Query/FunctionScoreQueryDescriptor.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public interface IFunctionScoreQuery : IQuery
3535

3636
[JsonProperty(PropertyName = "script_score")]
3737
IScriptFilter ScriptScore { get; set; }
38+
39+
[JsonProperty(PropertyName = "weight")]
40+
long? Weight { get; set; }
3841
}
3942

4043
public class FunctionScoreQuery : PlainQuery, IFunctionScoreQuery
@@ -52,6 +55,7 @@ protected override void WrapInContainer(IQueryContainer container)
5255
public float? MaxBoost { get; set; }
5356
public IRandomScoreFunction RandomScore { get; set; }
5457
public IScriptFilter ScriptScore { get; set; }
58+
public long? Weight { get; set; }
5559
}
5660

5761
public class FunctionScoreQueryDescriptor<T> : IFunctionScoreQuery where T : class
@@ -69,6 +73,8 @@ public class FunctionScoreQueryDescriptor<T> : IFunctionScoreQuery where T : cla
6973
IRandomScoreFunction IFunctionScoreQuery.RandomScore { get; set; }
7074

7175
IScriptFilter IFunctionScoreQuery.ScriptScore { get; set; }
76+
77+
long? IFunctionScoreQuery.Weight { get; set; }
7278

7379
bool IQuery.IsConditionless
7480
{
@@ -142,5 +148,11 @@ public FunctionScoreQueryDescriptor<T> ScriptScore(Action<ScriptFilterDescriptor
142148

143149
return this;
144150
}
151+
152+
public FunctionScoreQueryDescriptor<T> Weight(long weight)
153+
{
154+
((IFunctionScoreQuery)this).Weight = weight;
155+
return this;
156+
}
145157
}
146158
}

src/Tests/Nest.Tests.Unit/Search/Query/Singles/FunctionScoreQueryJson.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,30 @@ public void FunctionScoreQuery()
4747
Assert.True(json.JsonEquals(expected), json);
4848
}
4949

50+
[Test]
51+
public void FunctionScoreQueryWithJustWeight()
52+
{
53+
var s = new SearchDescriptor<ElasticsearchProject>().From(0).Size(10)
54+
.Query(q => q
55+
.FunctionScore(fs => fs
56+
.Query(qq => qq.MatchAll())
57+
.Weight(2)
58+
)
59+
);
60+
61+
var json = TestElasticClient.Serialize(s);
62+
var expected = @"{
63+
from: 0, size: 10,
64+
query : {
65+
function_score : {
66+
query : { match_all : {} },
67+
weight : 2
68+
}
69+
}
70+
}";
71+
Assert.True(json.JsonEquals(expected), json);
72+
}
73+
5074
[Test]
5175
public void FunctionScoreQueryConditionless()
5276
{

0 commit comments

Comments
 (0)