0
我正在使用官方elasticsearch-php客户端的以下请求。在elasticsearch中搜索精确值返回许多结果
private function getAllStatisticsByDomain() {
$params = [
'index' => 'stats',
'type' => 'domain_stats',
'size' => 99,
'body' => [
'query' => [
'match' => [
'domain' => 'http://veehouder.cono.nl',
],
],
],
];
$response = $this->getElasticClient()->search($params);
return $response['hits']['hits'];
}
前4个结果都具有场畴=>http://veehouder.cono.nl但它也检索不具有值“http://veehouder.cono.nl”(见屏幕截图)更多的结果。
我也有一个功能,这个请求工作正常,但在日期字段。
private function getAllStatisticsByDay() {
$params = [
'index' => 'stats',
'type' => 'domain_stats',
'size' => 99,
'body' => [
'query' => [
'match' => [
'date' => date('Y-m-d'),
],
],
],
];
$response = $this->getElasticClient()->search($params);
return $response['hits']['hits'];
}
有人可以请解释一下我为什么功能getAllStatisticsByDomain()获取更多的结果的话,我想要什么?
这是我的索引功能:
/**
* @param $id
* @param $domain
* @param $googlePSMobileScore
* @param $googlePSMobileUsabilityScore
* @param $googlePSDesktopScore
* @param $mozPDA
* @param $mozUPA
*/
function insert($id, $domain, $googlePSMobileScore, $googlePSMobileUsabilityScore, $googlePSDesktopScore, $mozPDA, $mozUPA, $date) {
$params = [
'index' => 'stats',
'type' => 'domain_stats',
'id' => $id,
'body' => [
'domain' => $domain,
'googlePSMobileScore' => $googlePSMobileScore,
'googlePSMobileUsabilityScore' => $googlePSMobileUsabilityScore,
'googlePSDesktopScore' => $googlePSDesktopScore,
'mozPDA' => $mozPDA,
'mozUPA' => $mozUPA,
'date' => $date,
],
];
getElasticClient()->index($params);
}
我的字段映射:
{
"stats": {
"mappings": {
"domain_stats": {
"properties": {
"date": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"domain": {
"type": "string"
},
"googlePSDesktopScore": {
"type": "long"
},
"googlePSMobileScore": {
"type": "long"
},
"googlePSMobileUsabilityScore": {
"type": "long"
},
"mozPDA": {
"type": "double"
},
"mozUPA": {
"type": "double"
}
}
}
}
}
}
尝试使用'term'而不是'match' – Val
运行'curl -XGET localhost:9200/stats/domain_stats/_mapping'时会得到什么? – Val
嗨瓦尔!我用curl -XGET localhost:9200/stats/domain_stats/_mapping返回的映射更新了我的问题 –