Elasticsearch使用多个filtersearch查询
大家好我是新的弹性search,但我已经通过基本的ElasticSearch 5.1文档。
问题在一行中:
search成功,但filter工作不正常。
映射数据types
{ "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所指出的,我也尝试过映射。 以下是我的映射
索引中的文档(Req-1)
.... { "_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" } }, ...
像上面一样,我有一个索引中的数百个文档
SEARCH QUERY FULL,我正在使用
"query": { "bool": { "must": { "multi_match" : { "query" : "mobile", "fields" : [ "title^5", "tags^4", "categories^3" ], "operator": "and" } }, "filter": { "bool" : { "must" : [ {"term" : {"status": "published"} } ] } } } }
-
在上面的查询中,最重要的search条件/filter是
{"term" : {"status": "published"} }
。 每个search结果都必须符合这个要求。 -
现在从结果列表中,我想过滤更多。 所以说,我只想得到有
mobile-marketing
作为tag
。 我的文档(Req-1)有这个tag
(mobile-marketing
)
现在的问题是:
如果我修改我的search查询,并添加我所需的filter ,如下所示:即使我的文档(Req-1)具有mobile-marketing
作为tag
我也没有search结果(点击率= 0)
"filter": { "bool" : { "must" : [ {"term" : {"status": "published"} }, {"term" : {"tags": "mobile-marketing"} } ] } }
但是如果我改变filter
{"tags": "mobile-marketing"}
TO{"tags": "mobile"}
,我得到所需的文档(Req-1) 。
我想使用这个filter获得同一个文档: {"tags": "mobile-marketing"}
。 那么我在哪里做错了?
我的search查询需要进行哪些修改?
谢谢
你的映射如何查找tags
?
看起来像你已经得到了分析 tags
领域的映射。 所分析的是,从书中 :
首先分析string,然后索引它。 换句话说,将该字段索引为全文。
所以首先分析一下,价值看起来像是移动营销 。 因此,由于中间的连字符,它将分开存储移动设备和市场营销,并将其标记为令牌。 即:将移动和营销存储到两个不同的令牌中。
而如果没有分析 :
索引此字段,因此它是可search的,但完全按照指定索引值。 不要分析它。
所以这将基本上存储的价值,而不分析它,这应该做你的情况的伎俩。 也许你也应该看看这一点 。
希望能帮助到你!
- 使用节点js进行弹性searchsorting
- ElasticSearch Nodejs Express自动化testing
- ElasticSearch _bulk调用导致“套接字挂起”,尽pipe体积小
- 有没有一种方法可以使用elasticsearch返回每个匹配字段只有一个命中?
- 在Heroku上为新的Firebase设置ElasticSearch上的Flashlight
- 在nodejs中使用elasticsearch获取基于属性值的文档
- Elasticsearch部署在2服务器负载均衡节点js应用程序设置中
- 如何在Elasticsearch中创build或replace文档?
- embedded式Mongoose的弹性search