【发布时间】:2017-03-17 01:00:55
【问题描述】:
我正在尝试使用 5.2 版在弹性搜索中编写 GROUP BY 查询
我想查询数据并将其限制为具有特定“标签”的数据。在下面的情况下。我想选择标题或内容字段中包含“FIY”一词的项目,然后缩小范围,以便仅搜索那些具有“FIY”和“竞赛”标签的文档
查询部分很好,但我正在努力将其限制为给定的标签。
到目前为止,我已经得到了,但我得到了错误。
"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”、“should”、“filter”或“must_not”。见elastic.co/guide/en/elasticsearch/reference/current/…
标签: elasticsearch kibana