问题描述:
我在查询关键词“新闻”时,返回了所有包含 “新闻” 关键词的数据。
此时我想让数据按时间先后顺序排序。
于是我添加 了sort 语法,但是搜索到的结果 以时间的先后顺序排列了,但是返回的结果中没有包含“新闻”关键字,(即query 查询语句使用sort 后,查询条件失效了。)
没有添加sort 排序的语法:
{
"from": 0,
"highlight": {
"fields": {
"content": {},
"description": {},
"title": {}
}
},
"query": {
"multi_match": {
"fields": [
"title",
"keywords",
"extensionkeywords",
"description",
"content"
],
"operator": "and",
"query": "新闻"
}
},
"size": 10
}
返回的部分数据如下:
(
[took] => 14
[timed_out] =>
[_shards] => Array
(
[total] => 5
[successful] => 5
[failed] => 0
)
[hits] => Array
(
[total] => 551
[max_score] => 45.696007
[hits] => Array
(
[0] => Array
(
[_index] => index
[_type] => honda
[_id] => 9826ccf56a4f76ff7c967598120bb48a
[_score] => 45.696007
[_source] => Array
以下是我添加sort的查询语法:
{
"from": 0,
"highlight": {
"fields": {
"content": {},
"description": {},
"title": {}
}
},
"query": {
"multi_match": {
"fields": [
"title",
"keywords",
"extensionkeywords",
"description",
"content"
],
"operator": "and",
"query": "新闻"
}
},
"size": 10,
"sort": [
{
"date": {
"order": "desc"
}
}
]
}
返回的数据
(
[took] => 15
[timed_out] =>
[_shards] => Array
(
[total] => 5
[successful] => 5
[failed] => 0
)
[hits] => Array
(
[total] => 551
[max_score] =>
[hits] => Array
(
[0] => Array
(
[_index] => index
[_type] => honda
[_id] => 9826ccf56a4f76ff7c967598120bb48a
[_score] =>
[_source] => Array
两次查询返回的 total 都是 551 , 但是 max_score 与 _score 不同
求大神帮我看一看为什么,怎么解决?
我在查询关键词“新闻”时,返回了所有包含 “新闻” 关键词的数据。
此时我想让数据按时间先后顺序排序。
于是我添加 了sort 语法,但是搜索到的结果 以时间的先后顺序排列了,但是返回的结果中没有包含“新闻”关键字,(即query 查询语句使用sort 后,查询条件失效了。)
没有添加sort 排序的语法:
{
"from": 0,
"highlight": {
"fields": {
"content": {},
"description": {},
"title": {}
}
},
"query": {
"multi_match": {
"fields": [
"title",
"keywords",
"extensionkeywords",
"description",
"content"
],
"operator": "and",
"query": "新闻"
}
},
"size": 10
}
返回的部分数据如下:
(
[took] => 14
[timed_out] =>
[_shards] => Array
(
[total] => 5
[successful] => 5
[failed] => 0
)
[hits] => Array
(
[total] => 551
[max_score] => 45.696007
[hits] => Array
(
[0] => Array
(
[_index] => index
[_type] => honda
[_id] => 9826ccf56a4f76ff7c967598120bb48a
[_score] => 45.696007
[_source] => Array
以下是我添加sort的查询语法:
{
"from": 0,
"highlight": {
"fields": {
"content": {},
"description": {},
"title": {}
}
},
"query": {
"multi_match": {
"fields": [
"title",
"keywords",
"extensionkeywords",
"description",
"content"
],
"operator": "and",
"query": "新闻"
}
},
"size": 10,
"sort": [
{
"date": {
"order": "desc"
}
}
]
}
返回的数据
(
[took] => 15
[timed_out] =>
[_shards] => Array
(
[total] => 5
[successful] => 5
[failed] => 0
)
[hits] => Array
(
[total] => 551
[max_score] =>
[hits] => Array
(
[0] => Array
(
[_index] => index
[_type] => honda
[_id] => 9826ccf56a4f76ff7c967598120bb48a
[_score] =>
[_source] => Array
两次查询返回的 total 都是 551 , 但是 max_score 与 _score 不同
求大神帮我看一看为什么,怎么解决?
1 个回复
medcl - 今晚打老虎。
赞同来自:
default_operator
}}}
不是operator
并且是大写的{{{
AND
}}}
文档连接:http://www.elasticsearch.org/g ... query