我有一份文件索引。索引包含文档主体和文档类型,例如pdf,jpeg,png等。我可以使用单词查询索引,并且使用一种文档类型必须很好。
$params = [
'index' => 'trial2',
'type' => '_doc',
'body' => [
'query' => [
'bool' => [
'must' => [
[ 'match' => [ 'file.extension' => "png" ] ],
[ 'match' => [ 'content' => "abc" ] ],
]
]
]
]
];
screenshot的挑战是,我想使用仍必须使用但具有文档类型数组(png但jpeg,gif,svg,tiff)的索引来查询索引,以便将其分类为图像。如何将png替换为数组,以便至少可以做到这一点。
答案 0 :(得分:0)
您可以使用“条款”查询:
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html
条款查询返回的文档在提供的字段中包含一个或多个确切的条款。
答案 1 :(得分:0)
file.extension
是text
类型:只需在Match Query旁边添加更多令牌即可。确保您通过this (Analysis)并转到this (Analyzer)以了解其内部工作方式。
POST my_png/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"file.extension": "jpg jpeg png" <---- Note this.
}
},
{
"match": {
"content": "abc"
}
}
]
}
}
}
file.extension
是keyword
类型(推荐)或者如果您在keyword
中有一个file.extension.keyword
兄弟姐妹,则可以使用Terms Query
POST my_png/_search
{
"query": {
"bool": {
"must": [
{
"terms": { <---- Terms Query
"file.extension.keyword": [ <---- Or 'file.extension' field, whichever must of be type `keyword`
"jpg",
"jpeg",
"png"
]
}
},
{
"match": {
"content": "abc"
}
}
]
}
}
}
根据您的要求,我想您必须使用第二个选项作为完全匹配项,因此您需要在Terms Query
字段上使用keyword
。
希望有帮助!