You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In order to sort by relevance, we need to represent relevance as a value. In
12
+
Elasticsearch, the _relevance score_ is represented by the floating-point
13
+
number returned in the search results as the `_score`, ((("relevance scores", "returned in search results score")))((("score", "relevance score of search results")))so the default sort
14
+
order is `_score` descending.
7
15
8
-
9
-
=== 排序
10
-
11
-
12
-
13
-
为了按照相关性来排序,需要将相关性表示为一个值。在elasticsearch中, _relevance score_ 是作为一个浮点数,并在结果中的 `_score` 返回,((("relevance scores", "returned in search results score")))((("score", "relevance score of search results")))因此默认排序是 `_score` 降序的。
Filters have no bearing on `_score`, and the((("score", seealso="relevance; relevance scores")))((("match_all query", "score as neutral 1")))((("filters", "score and"))) missing-but-implied `match_all`
37
+
query just sets the `_score` to a neutral value of `1` for all documents. In
38
+
other words, all documents are considered to be equally relevant.
37
39
38
-
==== 按照字段的值排序
40
+
==== Sorting by Field Values
39
41
40
-
41
-
在这个案例中,通过最近修改来排序是有意义的,最新的排在最前。((("sorting", "by field values")))((("fields", "sorting search results by field values")))((("sort parameter")))我们可以使用 `sort` 参数
42
+
In this case, it probably makes sense to sort tweets by recency, with the most
43
+
recent tweets first.((("sorting", "by field values")))((("fields", "sorting search results by field values")))((("sort parameter"))) We can do this with the `sort` parameter:
多重排序和 `_score` 并无不相关。你可以根据一些不同的字段进行排序,((("fields", "sorting by multiple fields"))),如地理距离或是脚本计算的特定值。
136
+
Multilevel sorting doesn't have to involve the `_score`. You could sort
137
+
by using several different fields,((("fields", "sorting by multiple fields"))) on geo-distance or on a custom value
138
+
calculated in a script.
129
139
130
140
[NOTE]
131
141
====
132
-
133
-
字符串查询((("sorting", "in query string searches")))((("sort parameter", "using in query strings")))((("query strings", "sorting search results for")))也支持特定排序,可以在查询字符串中使用 `sort` 参数
134
-
142
+
Query-string search((("sorting", "in query string searches")))((("sort parameter", "using in query strings")))((("query strings", "sorting search results for"))) also supports custom sorting, using the `sort` parameter
When sorting on fields with more than one value,((("sorting", "on multivalue fields")))((("fields", "multivalue", "sorting on"))) remember that the values do
154
+
not have any intrinsic order; a multivalue field is just a bag of values.
155
+
Which one do you choose to sort on?
147
156
157
+
For numbers and dates, you can reduce a multivalue field to a single value
158
+
by using the `min`, `max`, `avg`, or `sum` _sort modes_. ((("sum sort mode")))((("avg sort mode")))((("max sort mode")))((("min sort mode")))((("sort modes")))((("dates field, sorting on earliest value")))For instance, you
159
+
could sort on the earliest date in each `dates` field by using the following:
0 commit comments