我正在尝试使用 5.2 版在弹性搜索中编写 GROUP BY 查询
我想查询数据并将其限制为具有特定“标签”的数据。在以下情况下。我想选择标题或内容字段中包含“FIY”一词的项目,然后缩小范围,以便仅搜索具有“FIY”和“Competition”标签的文档
查询部分很好,但我正在努力将其限制为给定的标签。
到目前为止,我已经得到了,但我收到了错误。
"reason": "[bool] 查询不支持 [terms]",
GET advice-articles/_search
{
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "FIY",
"fields": ["title", "content"]
}
}
], "filter": {
"bool": {
"terms": {
"tags.tagName": [
"competition"
]
}
}
}
}
}
}
一个示例索引是
"_index": "advice-articles",
"_type": "article",
"_id": "1460",
"_score": 4.3167734,
"_source": {
"id": "1460",
"title": "Your top FIY tips",
"content": "Fix It Yourself in April 2012.",
"tags": [
{
"tagName": "Fix it yourself"
},
{
"tagName": "customer tips"
},
{
"tagName": "competition"
}
]
我的映射如下
{
"advice-articles": {
"mappings": {
"article": {
"properties": {
"content": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"tags": {
"type": "nested",
"properties": {
"tagName": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
}
}
}
}
}
}
}
}
bool 查询使用一个或多个布尔子句构建,每个子句都有一个类型化的出现。出现类型是:must
, must_not
, filter
,should
GET _search
{
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "FIY",
"fields": [
"title",
"content"
]
}
},
{
"nested": {
"path": "tags",
"query": {
"terms": {
"tags.tagName": [
"competition"
]
}
}
}
}
]
}
}
}
以下是如何使用 must 子句来满足您的查询要求。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句