大家好,我是弹性搜索的新手,但我已经阅读了基本的ElasticSearch 5.1文档。
一行中的问题:
搜索成功,但过滤器无法正常运行。
{
"properties": {
"title": {"type": "string"},
"description": {"type": "string"},
"slug": {"type": "string"},
"course_type": {"type": "string", "index" : "not_analyzed"},
"price": {"type": "string"},
"categories": {"type": "keyword", "index" : "not_analyzed"},
"tags": {"type" : "keyword"},
// "tags": {"type" : "keyword", "index" : "not_analyzed"},
"status": {"type" : "string","index" : "not_analyzed"},
}
}
正如@Darth_Vader所述,我也尝试过映射。以下是我的映射
....
{
"_index": "learnings",
"_type": "materials",
"_id": "582d9xxxxxxxx9b27fab2c",
"_score": 1,
"_source": {
"title": "Mobile Marketing",
"slug": "mobile-marketing",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla eleifend hendrerit vehicula.",
"categories": [
"Digital Marketing"
],
"tags": [
"digital-marketing",
"mobile-marketing"
],
"status": "published"
}
},
...
如上所述,我在索引中有100个文档
"query": {
"bool": {
"must": {
"multi_match" : {
"query" : "mobile",
"fields" : [ "title^5", "tags^4", "categories^3" ],
"operator": "and"
}
},
"filter": {
"bool" : {
"must" : [
{"term" : {"status": "published"} }
]
}
}
}
}
在上述查询中,最重要的搜索条件/过滤条件为 {"term" :
{"status": "published"} }
。每个搜索结果都必须满足此要求
要求。
现在从结果列表中,我想要过滤更多。所以说我想只获得{strong> documents
mobile-marketing
作为 tag
。我的文档(Req-1)有 tag
(mobile-marketing
)
如果我修改搜索查询并添加我所需的 过滤器 ,如下所示:我没有搜索结果(hits = 0)即使我的文档(Req-1) mobile-marketing
tag
"filter": {
"bool" : {
"must" : [
{"term" : {"status": "published"} },
{"term" : {"tags": "mobile-marketing"} }
]
}
}
但如果我更改过滤器
{"tags": "mobile-marketing"}
TO{"tags": "mobile"}
,我会收到所需的文件(Req-1)结果。
我希望使用此过滤器获取相同的文档: {"tags": "mobile-marketing"}
。那我在哪里做错了?
我的搜索查询需要进行哪些修改?
由于