在elasticsearch中检索多个唯一字段的最佳方法

时间:2014-02-11 09:12:51

标签: search elasticsearch

我有以下由elasticsearch索引的示例数据:

{"ip": "192.168.1.1", "port": "22", "protocol": "TCP", other fields...},
{"ip": "192.168.1.2", "port": "53", "protocol": "UDP", other fields...},
{"ip": "192.168.1.1", "port": "22", "protocol": "TCP", other fields...},
{"ip": "192.168.1.1", "port": "23", "protocol": "TCP", other fields...},
{"ip": "10.1.1.2", "port": "53", "protocol": "UDP", other fields...},
...

我想收到所有唯一的(ip,端口,协议)。首先,我使用以下查询来接收唯一的“ip”,我将大小设置为一个大数字来获取所有结果:

curl -XPOST 'http://localhost:9200/logs/access/_search?pretty=true' -d '
{
 "query" : { "match_all": {} },
 "facets": {
  "ip": {
   "terms": {"field": "ip", "size": 9999999}
  }
 }
}'

然后我查询每个“ip”以接收唯一端口列表,例如

curl -XPOST 'http://localhost:9200/logs/access/_search?pretty=true' -d '
{
 "query" : { "match": {"ip": "192.168.1.2"}},
 "facets": {
  "port": {
   "terms": {"field": "port", "size": 9999999}
  }
 }
}'

然后查询每个“ip”和“port”以获得“协议”字段的相关性。

我觉得这是实现这个目标的好方法!那么,接收这个独特(ip,端口,协议)元组的最佳或优化方式是什么?

0 个答案:

没有答案