[英]PHP Elasticsearch, bool query with filter not getting any result
因此,我试图在“名称”字段中找到所有包含“ ssh”的文档,其中“版本”字段等于12.1.2、12.1.1等。这是我的参数:
$params = [
'index' => 'notes',
'type' => 'release',
'body' => [
'query' => [
'bool' => [
'must' => [
'match' => [ 'name' => 'ssh' ]
],
'filter' => [
'term' => [ 'versions' => '12.1.2, 12.1.1, 12.1.0' ]
]
]
]
]
];
这是一个示例文件:
Array
(
[_index] => notes
[_type] => release
[_id] => AVo3jnT2RJ1Gn1RjrM7p
[_score] => 0.52541894
[_source] => Array
(
[name] => 621423 : sys-icheck reports error with /config/ssh/ssh_host_dsa_key
[component] => TMOS
[symptoms] => On Azure cloud, running sys-icheck may report an error with /config/ssh/ssh_host_dsa_key and other files: ERROR: missing /config/ssh/ssh_host_dsa_key ERROR: missing /config/ssh/ssh_host_dsa_key.pub ERROR: missing /config/ssh/ssh_host_key ERROR: missing /config/ssh/ssh_host_key.pub
[conditions] => This occurs on BIG-IP running on Azure cloud.
[impact] => sys-icheck utility indicates an error. The sys-icheck utility is used to find file system changes that have occurred since initial installation and provide information about their status.
[workaround] =>
[fix] => Fixed an issue with files in /config/ssh/ that was causing sys-icheck to report errors.
[versions] => 12.1.2, 12.1.1, 12.1.0
)
)
根据要求,这是name
映射:
{
notes: {
mappings: {
release: {
name: {
full_name: "name"
mapping: {
name: {
type: "text"
fields: {
keyword: {
type: "keyword"
ignore_above: 256
} -
} -
} -
} -
} -
} -
} -
} -
}
/ GET / notes的结果:
{
notes: {
aliases: {}
mappings: {
release: {
properties: {
component: {
type: "text"
fields: {
keyword: {
type: "keyword"
ignore_above: 256
} -
} -
} -
conditions: {
type: "text"
fields: {
keyword: {
type: "keyword"
ignore_above: 256
} -
} -
} -
fix: {
type: "text"
fields: {
keyword: {
type: "keyword"
ignore_above: 256
} -
} -
} -
impact: {
type: "text"
fields: {
keyword: {
type: "keyword"
ignore_above: 256
} -
} -
} -
name: {
type: "text"
fields: {
keyword: {
type: "keyword"
ignore_above: 256
} -
} -
} -
symptoms: {
type: "text"
fields: {
keyword: {
type: "keyword"
ignore_above: 256
} -
} -
} -
versions: {
type: "text"
fields: {
keyword: {
type: "keyword"
ignore_above: 256
} -
} -
} -
workaround: {
type: "text"
fields: {
keyword: {
type: "keyword"
ignore_above: 256
} -
} -
} -
} -
} -
} -
settings: {
index: {
creation_date: "1486999820715"
number_of_shards: "5"
number_of_replicas: "1"
uuid: "SZfFCZ-HRT6Yr17epsv2-Q"
version: {
created: "5020099"
} -
provided_name: "notes"
} -
} -
} -
}
过滤器是唯一的工作语句,因为我已获取所有12.1.2文档。 有任何想法吗?
这是因为字段name
analyzer
设置为keyword
。 当您这样做时,它不会标记关键字。 因此,在这里您将必须使用全文搜索该文档。
意思是如果您must
在下面使用它,它将为您提供输出。
621423 : sys-icheck reports error with /config/ssh/ssh_host_dsa_key
在此处查看keyword anlyzer
以下查询对我有用,即您需要对versions
使用terms
查询,并且每个版本都有一个数组。
$params = [
'index' => 'notes',
'type' => 'release',
'body' => [
'query' => [
'bool' => [
'must' => [
'match' => [ 'name' => 'ssh' ]
],
'filter' => [
'terms' => [
'versions' => ['12.1.2', '12.1.1', '12.1.0']
]
]
]
]
]
];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.