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

时间:2017-09-12 07:22:12

标签: 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上查询以查找带有http或https的url的出现。

至于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
                           } }


                           }

                      )

在此

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

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

2 个答案:

答案 0 :(得分:1)

自己得到了答案

public class MyConfigBalanceRule extends ClientConfigEnabledRoundRobinRule {
    @Override
    public Server choose(Object key) {
        List<Server> serverList = getLoadBalancer().getAllServers();
        for (Server srv : serverList) {
            if (srv.getPort == key) {
                return srv;
            }
        }
    }
}

答案 1 :(得分:0)

尝试此查询

如果分析了数据字段URL,那么这将起作用:

{
   "query": {
         "query_string": {
                    "query": "url: (http OR https) "
            }
   }
}

同样在查询中使用斜杠时,请确保将其转义。

相关问题