1

I have the following mapping (I'm using elasticsearch5)

curl -XPUT 'http://localhost:9200/server_logs8?pretty' -d '
{
  "mappings": {
    "kafka-connect": {
      "properties": {
        "message": {
          "type": "string"
        },
        "server_name": {
          "type": "string"
        },
        "timestamp": {
          "type": "date"
        }
      }
    }
  }
}
'

I'm looking for a specific faulty behaviour on my servers, and I need to know which servers are affected. To find them I need to do the following

Find all the server_id that have both "message_a" and "message_b"

for example if I have the documents (one by line)

{"server_id": 1 , "message":  "message_a"}
{"server_id": 1 , "message":  "message_c"}
{"server_id": 1 , "message":  "message_b"}

{"server_id": 2 , "message":  "message_d"}
{"server_id": 2 , "message":  "message_a"}

{"server_id": 3 , "message":  "message_a"}
{"server_id": 3 , "message":  "message_b"}

I want it to return me [1, 3]

Is it possible to do this with ElasticSearch in one query ?

Currently I'm doing a first request "message_a" and then a second request "message_b", and I do the intersection of the two set of "server_id" i got, but I would like to do that in one request (especially if I can create a visuazation in Kibana from there)

allan.simon
  • 3,886
  • 6
  • 35
  • 60

0 Answers0