[英]Filter on Elasticsearch terms query
我正在寻找任何用户最后一次登录的时间。
我有两种身份验证类型(管理员、客户端),并且正在尝试执行查询以查找事件:身份验证成功其中身份验证类型:客户端
我最接近的是:
params='{ "query":{"terms":{"event_type":["authentication_succeeded"]}}}'
data=$(curl -XGET "localhost:9200/logstash-*/_search?scroll=10m&size=500&pretty" -H 'Content-Type: application/json' -d"${params}")
经过许多变化和替代查询类型,但我无法成功附加过滤器 '{"authentication_type":"Client"}'
您需要将authentication_type
和event_type
定义为关键字,然后在搜索查询中对这些字段使用术语过滤器。
您可以在此官方 ES 链接中阅读带有多个术语的示例过滤器。
下面是一个分步示例,它使用您的数据来显示预期的搜索结果。
{
"mappings": {
"properties": {
"authentication_type": {
"type": "keyword"
},
"event_type" :{
"type" : "keyword"
}
}
}
}
{
"authentication_type" : "Client",
"event_type" : "authentication_succeeded"
}
{
"authentication_type" : "Client",
"event_type" : "authentication_failed"
}
{
"authentication_type" : "Admin",
"event_type" : "authentication_succeeded"
}
{
"authentication_type" : "Admin",
"event_type" : "authentication_failed"
}
{
"query": {
"bool": {
"filter": [
{
"term": {
"event_type": "authentication_succeeded"
}
},
{
"term": {
"authentication_type": "Client"
}
}
]
}
}
}
"hits": [
{
"_index": "so_60750542",
"_type": "_doc",
"_id": "1",
"_score": 0.0,
"_source": {
"authentication_type": "Client",
"event_type": "authentication_succeeded"
}
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.