[英]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.