elasticsearch - 在elasticsearch中搜索同一字段的多个值

标签 elasticsearch

我有这样的模式

[{'author': 'edsec',
'awesomeness': 3,
'date': '2017-09-12T07:22:50.033712',
'url': 'http://nakedsecurity.sophos.com/2016/02/11/'},
{'author': '.thea',
'awesomeness': 2,
'date': '2017-09-12T08:22:49.969594',
'url': 'http://www.theage.com.au/victoria/'},
{'author': '.chic',
'awesomeness': 1,
'date': '2017-09-12T09:22:49.896584',
 'url': 'http://www.chicagotribune.com/news/'},
{'author': '://ww',
'awesomeness': 1,
'date': '2017-09-12T10:19:58.723068',
'url': 'https://www.theage.com.au/victoria/'},
{'author': '://ww',
'awesomeness': 0,
'date': '2017-09-12T11:19:58.656548',
'url': 'https://www.networkworld.com/article/3028099/security/'},
{'author': '://av',
'awesomeness': 0,
'date': '2017-09-12T12:19:57.589412',
'url': 'https://avien.net/blog/educational-ransomware/'}]

现在我想查询 url 以查找 url 与 http 或 https 的出现。

关于 url http://www.theage.com.au/victoria/我想丢弃的 http 和 https 版本都已保存。

我进行了一些搜索并编写了查询,但没有给出足够的结果。

result = es.search(index='blogs', doc_type='text',  
                       body={
                           "size": 10,
                           "query": {"bool":{
                                  "should":[
                                  {"term": {"url": final_url}},
                                  {"term": {"url": url}}],
                                  "minimum_should_match" : 1,
                                  "boost" : 1.0
                           } }


                           }

                      )

在这

网址 = http://www.networkworld.com/article/3028099/security/ final_url = https://www.networkworld.com/article/3028099/security/

我变空了,没有匹配的结果,我应该得到其中一个。

最佳答案

我自己得到了答案

    result = es.search(index=self.es_index, doc_type='abc',
                       body={"query": {"bool":{
                                  "must":[
                                  {"match": {"url": url}},
                                  {"match": {"url": url2}}],

                           } }})

关于elasticsearch - 在elasticsearch中搜索同一字段的多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46170309/

相关文章:

elasticsearch - NEST版本1.3.1支持的Elasticsearch版本

elasticsearch - 不需要在ElasticSearch中搜索的字段

elasticsearch - 具有相同类型的 Elasticsearch 父级

ElasticSearch 边缘NGram

elasticsearch - 在某些字段上完全匹配,在其他字段上搜索 “fuzzy”吗?

elasticsearch - 基巴纳 : Coordinate Map: Could not retrieve manifest from the tile service: status -1

mongodb - 如何使用 mongo-connector 连接到远程 MongoDB?

elasticsearch - ElasticSearch衰减最小值

logstash - Logstash不写入/处理数据,并且似乎无提示地失败

c# - 通过Nest在Elasticsearch中使用同义词