Skip to content

Commit 914f366

Browse files
committed
Merge branch 'fix/2.x-rescore-query' into 2.x
2 parents 63b1fa6 + 40362cf commit 914f366

File tree

19 files changed

+634
-31
lines changed

19 files changed

+634
-31
lines changed

docs/breaking-changes.asciidoc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
--
66
There are a number of breaking changes when going from 1.x to 2.x
77

8-
98
* <<elasticsearch-net-breaking-changes, Elasticsearch.Net Breaking Changes>>
109

1110
* <<nest-breaking-changes, NEST Breaking Changes>>

docs/client-concepts/high-level/inference/field-inference.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ var fieldExpression = Infer.Field<Project>(p => p.Name);
130130
----
131131

132132
this can be even shortened even further using a https://msdn.microsoft.com/en-us/library/sf0df423.aspx#Anchor_0[static import in C# 6] i.e.
133-
`using static Nest.Infer;`
133+
`using static Nest.Infer;`
134134

135135
[source,csharp]
136136
----

docs/client-concepts/low-level/connecting.asciidoc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,22 @@ var settings = new ConnectionConfiguration(uri);
148148

149149
There are three categories of exceptions that may be thrown:
150150

151-
`ElasticsearchClientException`::
151+
`ElasticsearchClientException`::
152+
152153
These are known exceptions, either an exception that occurred in the request pipeline
153154
(such as max retries or timeout reached, bad authentication, etc...) or Elasticsearch itself returned an error (could
154155
not parse the request, bad query, missing field, etc...). If it is an Elasticsearch error, the `ServerError` property
155156
on the response will contain the the actual error that was returned. The inner exception will always contain the
156157
root causing exception.
157158

158-
`UnexpectedElasticsearchClientException`::
159+
`UnexpectedElasticsearchClientException`::
160+
159161
These are unknown exceptions, for instance a response from Elasticsearch not
160162
properly deserialized. These are usually bugs and {github}/issues[should be reported]. This exception also inherits from `ElasticsearchClientException`
161163
so an additional catch block isn't necessary, but can be helpful in distinguishing between the two.
162164

163-
Development time exceptions::
165+
Development time exceptions::
166+
164167
These are CLR exceptions like `ArgumentException`, `ArgumentOutOfRangeException`, etc.
165168
that are thrown when an API in the client is misused.
166169
These should not be handled as you want to know about them during development.

docs/common-options.asciidoc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
--
88
NEST has a number of types for working with Elasticsearch conventions for:
99

10-
1110
* <<time-units, Time Units>>
1211

1312
* <<distance-units, Distance Units>>

docs/high-level.asciidoc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,18 @@
66
[partintro]
77
--
88
The high level client, `ElasticClient`, provides a strongly typed query DSL that maps one-to-one with the Elasticsearch query DSL.
9-
109
It can be installed from the Package Manager Console inside Visual Studio using
1110

12-
1311
[source,shell]
1412
----
1513
Install-Package NEST
1614
----
1715

18-
1916
Or by searching for https://www.nuget.org/packages/NEST[NEST] in the Package Manager GUI.
20-
2117
NEST internally uses and still exposes the low level client, `ElasticLowLevelClient`, from <<elasticsearch-net,Elasticsearch.Net>> via
2218
the `.LowLevel` property on `ElasticClient`.
23-
2419
There are a number of conventions that NEST uses for inference of
2520

26-
2721
* <<index-name-inference, Index Names>>
2822

2923
* <<indices-paths, Building a URI path to one or more indices>>
@@ -36,10 +30,8 @@ There are a number of conventions that NEST uses for inference of
3630

3731
* <<features-inference, API features>>
3832

39-
4033
In addition to features such as
4134

42-
4335
* <<auto-map, Auto Mapping C# types>>
4436

4537
* <<covariant-search-results, Covariant Search Results>>

docs/low-level.asciidoc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@
77
--
88
The low level client, `ElasticLowLevelClient`, is a low level, dependency free client that has no
99
opinions about how you build and represent your requests and responses.
10-
1110
It can be installed from the Package Manager Console inside Visual Studio using
1211

13-
1412
[source,shell]
1513
----
1614
Install-Package Elasticsearch.Net
1715
----
1816

19-
2017
Or by searching for https://www.nuget.org/packages/Elasticsearch.Net[Elasticsearch.Net] in the Package Manager GUI.
2118

2219
--

docs/search-usage.asciidoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
:includes-from-dirs: search/request
1+
:includes-from-dirs: search/request,search/search/rescoring
22

33
include::search/request/explain-usage.asciidoc[]
44

@@ -30,3 +30,5 @@ include::search/request/source-filtering-usage.asciidoc[]
3030

3131
include::search/request/suggest-usage.asciidoc[]
3232

33+
include::search/search/rescoring/rescore-usage.asciidoc[]
34+

docs/search.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ NEST exposes all of the search request parameters available in Elasticsearch
3535

3636
* <<suggest-usage,Suggest Usage>>
3737

38+
* <<rescore-usage,Rescore Usage>>
39+
3840
--
3941

4042
include::search-usage.asciidoc[]

docs/search/request/from-and-size-usage.asciidoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
Pagination of results can be done by using the `from` and `size` parameters.
1111

12-
`from` parameter::
12+
`from` parameter::
13+
1314
defines the offset from the first result you want to fetch.
1415

15-
`size` parameter::
16+
`size` parameter::
17+
1618
allows you to configure the maximum amount of hits to be returned.
1719

1820
=== Object Initializer Syntax Example
Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
:ref_current: https://www.elastic.co/guide/en/elasticsearch/reference/2.3
2+
3+
:github: https://github.com/elastic/elasticsearch-net
4+
5+
:nuget: https://www.nuget.org/packages
6+
7+
[[rescore-usage]]
8+
== Rescore Usage
9+
10+
Rescoring can help to improve precision by reordering just the top (eg 100 - 500) documents
11+
returned by the query and post_filter phases, using a secondary (usually more costly) algorithm,
12+
instead of applying the costly algorithm to all documents in the index.
13+
14+
See the Elasticsearch documentation on {ref_current}/search-request-rescore.html[Rescoring] for more detail.
15+
16+
[[single-rescore-query]]
17+
[float]
18+
== Single rescore query
19+
20+
=== Fluent DSL Example
21+
22+
[source,csharp]
23+
----
24+
s => s
25+
.From(10)
26+
.Size(20)
27+
.Query(q => q
28+
.MatchAll()
29+
)
30+
.Rescore(r => r
31+
.WindowSize(20)
32+
.RescoreQuery(rq => rq
33+
.ScoreMode(ScoreMode.Multiply)
34+
.Query(q => q
35+
.ConstantScore(cs => cs
36+
.Filter(f => f
37+
.Terms(t => t
38+
.Field(p => p.Tags.First())
39+
.Terms("eos", "sit", "sed")
40+
)
41+
)
42+
)
43+
)
44+
)
45+
)
46+
----
47+
48+
=== Object Initializer Syntax Example
49+
50+
[source,csharp]
51+
----
52+
new SearchRequest<Project>
53+
{
54+
From = 10,
55+
Size = 20,
56+
Query = new QueryContainer(new MatchAllQuery()),
57+
Rescore = new Rescore
58+
{
59+
WindowSize = 20,
60+
Query = new RescoreQuery
61+
{
62+
ScoreMode = ScoreMode.Multiply,
63+
Query = new ConstantScoreQuery
64+
{
65+
Filter = new TermsQuery
66+
{
67+
Field = Infer.Field<Project>(p => p.Tags.First()),
68+
Terms = new[] { "eos", "sit", "sed" }
69+
}
70+
}
71+
}
72+
}
73+
74+
}
75+
----
76+
77+
[source,javascript]
78+
.Example json output
79+
----
80+
{
81+
"from": 10,
82+
"size": 20,
83+
"query": {
84+
"match_all": {}
85+
},
86+
"rescore": {
87+
"window_size": 20,
88+
"query": {
89+
"score_mode": "multiply",
90+
"rescore_query": {
91+
"constant_score": {
92+
"filter": {
93+
"terms": {
94+
"tags": [
95+
"eos",
96+
"sit",
97+
"sed"
98+
]
99+
}
100+
}
101+
}
102+
}
103+
}
104+
}
105+
}
106+
----
107+
108+
[[multiple-rescore-queries]]
109+
[float]
110+
== Multiple rescore queries
111+
112+
=== Fluent DSL Example
113+
114+
[source,csharp]
115+
----
116+
s => s
117+
.From(10)
118+
.Size(20)
119+
.Query(q => q
120+
.MatchAll()
121+
)
122+
.Rescore(r => r
123+
.WindowSize(20)
124+
.RescoreQuery(rq => rq
125+
.ScoreMode(ScoreMode.Multiply)
126+
.Query(q => q
127+
.ConstantScore(cs => cs
128+
.Filter(f => f
129+
.Terms(t => t
130+
.Field(p => p.Tags.First())
131+
.Terms("eos", "sit", "sed")
132+
)
133+
)
134+
)
135+
)
136+
)
137+
)
138+
.Rescore(rr => rr
139+
.RescoreQuery(rq => rq
140+
.ScoreMode(ScoreMode.Total)
141+
.Query(q => q
142+
.FunctionScore(fs => fs
143+
.Functions(f => f
144+
.RandomScore(1337)
145+
)
146+
)
147+
)
148+
)
149+
)
150+
----
151+
152+
=== Object Initializer Syntax Example
153+
154+
[source,csharp]
155+
----
156+
new SearchRequest<Project>
157+
{
158+
From = 10,
159+
Size = 20,
160+
Query = new QueryContainer(new MatchAllQuery()),
161+
Rescore = new MultiRescore
162+
{
163+
new Rescore
164+
{
165+
WindowSize = 20,
166+
Query = new RescoreQuery
167+
{
168+
ScoreMode = ScoreMode.Multiply,
169+
Query = new ConstantScoreQuery
170+
{
171+
Filter = new TermsQuery
172+
{
173+
Field = Infer.Field<Project>(p => p.Tags.First()),
174+
Terms = new[] { "eos", "sit", "sed" }
175+
}
176+
}
177+
}
178+
},
179+
new Rescore
180+
{
181+
Query = new RescoreQuery
182+
{
183+
ScoreMode = ScoreMode.Total,
184+
Query = new FunctionScoreQuery
185+
{
186+
Functions = new List<IScoreFunction>
187+
{
188+
new RandomScoreFunction
189+
{
190+
Seed = 1337
191+
}
192+
}
193+
}
194+
}
195+
}
196+
}
197+
}
198+
----
199+
200+
[source,javascript]
201+
.Example json output
202+
----
203+
{
204+
"from": 10,
205+
"size": 20,
206+
"query": {
207+
"match_all": {}
208+
},
209+
"rescore": [
210+
{
211+
"window_size": 20,
212+
"query": {
213+
"score_mode": "multiply",
214+
"rescore_query": {
215+
"constant_score": {
216+
"filter": {
217+
"terms": {
218+
"tags": [
219+
"eos",
220+
"sit",
221+
"sed"
222+
]
223+
}
224+
}
225+
}
226+
}
227+
}
228+
},
229+
{
230+
"query": {
231+
"score_mode": "total",
232+
"rescore_query": {
233+
"function_score": {
234+
"functions": [
235+
{
236+
"random_score": {
237+
"seed": 1337
238+
}
239+
}
240+
]
241+
}
242+
}
243+
}
244+
}
245+
]
246+
}
247+
----
248+

0 commit comments

Comments
 (0)