【发布时间】:2018-06-08 17:29:36
【问题描述】:
信息:使用“yiisoft/yii2-elasticsearch”:“2.1.x-dev”
我想使用 yii2 elastic 执行以下操作: (来自https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html)
{
"sort" : [
{
"_geo_distance" : {
"location" : {
"lat" : -33.936593,
"lon" : 18.4204544
},
"order" : "asc",
"unit" : "km"
}
}
],
"query": {
"bool" : {
"must" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "3000km",
"location" : {
"lat" : -33.936593,
"lon" : 18.4204544
}
}
}
}
}
}
当我使用以下内容时:
$query = [
'bool' => [
// 'must' => [
// 'match_all' => [] // this throws a diff error
// ],
'filter' => [
'geo_distance' => [
'distance' => $distance . "km",
'location' => [
'lat' => $lat,
'lon' => $lng
]
]
]
]
];
$sort = [
'geo_distance' => [
'location' => [
'lat' => $lat,
'lon' => $lng
],
'order' => 'asc',
'unit' => 'km'
]
];
$models = Model::find()
->query($query)
->orderBy($sort)
->all();
我得到错误:
异常 'yii\elasticsearch\Exception' 带有消息 'Elasticsearch 请求失败,代码为 400。响应正文: {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"[field_sort] 未知字段 [位置],解析器不是 找到"}],"type":"illegal_argument_exception","reason":"[field_sort] 未知字段 [位置],未找到解析器"},"status":400}'
也许我可以将原始 json 查询传递给 yii2 elasticsearch?不确定 yii2-elasticsearch 库是否能够处理“位置”(geo_distance)字段?
帮助表示赞赏, 万托
【问题讨论】:
标签: yii2