【发布时间】:2016-01-03 21:44:14
【问题描述】:
我有一个名为 url 的字段,当我对其进行索引时,它被设置为 not_analyzed:
'url' => [
'type' => 'string',
'index' => 'not_analyzed'
]
这是我确定索引中是否已存在 URL 的方法:
public function urlExists($index, $type, $url) {
$params = [
'index' => $index,
'type' => $type,
'body' => [
'query' => [
'match' => [
'url' => $url
]
]
]
];
$results = $this->client->count($params);
return ($results['count'] > 0);
}
这似乎工作正常,但我不能 100% 确定这是找到完全匹配的正确方法,因为阅读文档的另一种方法是使用以下参数进行搜索:
$params = [
'index' => $index,
'type' => $type,
'body' => [
'query' => [
'filtered' => [
'filter' => [
'term' => [
'url' => $url
]
]
]
]
]
];
我的问题是,对于 not_analyzed 字段,任一参数的工作方式是否相同?
【问题讨论】:
标签: php elasticsearch