是否可以选择通过索引设置或映射中的某些更改按字母顺序排序?
我知道有一种"排序"查询,但删除了分数,除了按字母顺序排列之外,我还要考虑分数。
例如,如果结果" A" &安培; " Z"得分为2," C"得分为1我希望订单为:
A
ž
C
这可能吗?
这是我当前的索引设置和映射:
public class VolleyRequest extends JsonObjectRequest {
String email, pass;
boolean saveCookeis;
public VolleyRequest(int method, String url, JSONObject jsonRequest,
Listener<JSONObject> listener, ErrorListener errorListener,
String email, String pass, boolean saveCookie) {
super(method, url, jsonRequest, listener, errorListener);
// TODO Auto-generated constructor stub
this.email = email;
this.pass = pass;
this.saveCookeis = saveCookie;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
// TODO Auto-generated method stub
HashMap<String, String> params = new HashMap<String, String>();
String auth = "";
try {
auth = android.util.Base64.encodeToString(
(this.email + ":" + this.pass).getBytes("UTF-8"),
android.util.Base64.DEFAULT);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
params.put("Authorization", auth);
return params;
}
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
// TODO Auto-generated method stub
if (saveCookeis) {
try {
String jsonString = new String(response.data,
HttpHeaderParser.parseCharset(response.headers));
ApplicationController.getInstance().checkSessionCookie(
response.headers);
return Response.success(new JSONObject(jsonString),
HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} catch (JSONException je) {
return Response.error(new ParseError(je));
}
}
return super.parseNetworkResponse(response);
}
}
是否可以在索引设置中添加内容,以便按字母顺序自动排序结果?
答案 0 :(得分:4)
ElasticSearch的文档中的example表明您应该能够按多个值排序,包括_score
。尝试类似:
"sort": [
{ "date": { "order": "desc" }},
{ "_score": { "order": "desc" }}
]
我不确定您要尝试排序的字段,因此您需要根据需要调整上述示例。
请告诉我这是否适合您:)