elasticsearch,Search,elasticsearch" /> elasticsearch,Search,elasticsearch" />

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

在elasticsearch中检索多个唯一字段的最佳方法,search,elasticsearch,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

我有以下由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”和“端口”以获得相关的“协议”字段


我觉得这是值得的方式来实现这一点!因此,接收这个唯一(ip、端口、协议)元组的最佳或优化方法是什么?

我认为在编制索引时,您可以为多个字段编制索引,其中的内容是(ip、端口、协议)的组合值,例如:
protocol@ip:端口
。然后,你可以在这个组合场上做分面,这是一个好的技巧。我想有一个只包含唯一元组的分离索引。我还发现,有人在讨论向ES1.0添加聚合功能,以结束这些分组闹剧-