我使用5.2版本GROUP BY在elasticsearch
想寫一個GROUP BY查詢彈性搜索我要查詢的數據,並限制下來到那些有特定的「標籤」。在下面的情況下。我想在標題或內容字段中選擇包含單詞「FIY」的項目,然後將其縮小以僅搜索具有標籤「FIY」和「Competition」的文檔。
查詢部分很好但我正在努力限制它給定的標籤。
到目前爲止,我得到了,但我得到的錯誤。
「原因」: 「[BOOL]查詢不支持[條款]」,
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"
}
}
}
}
}
}
}
}
}
}
我認爲當你寫「布爾」時必須遵循「必須」,「應該」,「過濾器」或「must_not」。請參閱https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html – Adonis