ES v5:
Recherche dans plusieurs index identifiés, avec filtre des champs de sortie
1 curl -XGET http://127.0.0.1:9200/logstash-rproxy-2017.02.20,logstash-rproxy-2017.02.21,logstash-rproxy-2017.02.23/search?pretty= y -d '
2 {
3 " source" : ["URL", "user_agent","user"],
4 "query": {
5 "bool": {
6 "must": [
7 { "match": { "URL.raw": "/public" }},
8 { "match": { "application": "extranet1" }}
9 ]
10 }
11 }
12 }'
Recherche dans tous les index avec un filtre sur la date et champs de sortie
1 curl -XGET http://127.0.0.1:9200/logstash-rproxy-*/search?pretty= y -d '
2 {
3 " source" : ["URL", "user_agent","user"],
4 "query": {
5 "bool": {
6 "must": [
7 { "match": { "URL.raw": "/public" }},
8 { "match": { "application": "extranet1" }}
9 ],
10 "must": [
11 {
12 "range": {
13 "@timestamp" : {
14 "gte": "18/12/2016",
15 "lte": "now",
16 "format": "dd/MM/yyyy||yyyy"
17 }
18 }
19 }
20 ]
21 }
22 }
23 }'
Recherche avec filtre dans l'URL
1 curl -XGET 'localhost:9200/logstash-rp-2017.02.01/search?q=unique_id=O97KxMCoAncAAIi9easABHjI9&pretty=true'
2 {
3 "took" : 3 ,
4 "timed_out" : false,
5 "shards" : {
6 "total" : 5 ,
7 "successful" : 5 ,
8 "failed" : 0
9 } ,
10 "hits" : {
11 "total" : 1 ,
12 "max_score" : 13 .215996,
13 "hits" : [
14 {
15 "index" : "logstash-rp-2017.02.01" ,
16 "type" : "syslog" ,
17 "id" : "AVqjbBC52M9ghcpEcwy3" ,
18 "score" : 13 .215996,
19 "_source" : {
20 ....
Recherche avec filtre et filtre de sortie dans l'URL
1 curl -XGET 'localhost:9200/logstash-rp-2017.02.01/search?q=unique_id=09ixMCkL5cAAIi9easJUYBx&pretty=true&filter_path=hits.hits. source.program,hits.hits.source.port'
2 {
3 "hits" : {
4 "hits" : [
5 {
6 "source" : {
7 "program" : "/opt/sol/bin/rp" ,
8 "port" : 56031
9 }
10 }
11 ]
12 }
13 }
Recherche en fuzzy/proximiyté
1 curl -XGET http://127.0.0.1:9200/logstash-rproxy-2017.02.20,logstash-rproxy-2017.02.21,logstash-rproxy-2017.02.23/_search?pretty= y -d '
2 {
3 "query": {
4 "bool": {
5 "must": [
6 { "fuzzy": { "URL.raw": "/pulic" }},
7 { "match": { "application": "extranet1" }}
8 ]
9 }
10 }
11 }'
Note : ES limite à 10 réponses par défaut (possibilité de à 10000 max avec le paramétre size), il peut-être intéressant de connaître le nombre total de réponses en remplaçant _search par _count .
ES v2 :
Recherche dans tous les index avec un filtre sur la date et champs de sortie
1 curl -XGET http://127.0.0.1:9200/_search?pretty= y -d '
2 {
3 "fields" : ["URL", "user_agent","user"],
4 "query": {
5 "bool": {
6 "must": [
7 { "match": { "URL.raw": "/public" }},
8 { "match": { "application": "extranet1" }}
9 ],
10 "must": [
11 {
12 "range": {
13 "@timestamp" : {
14 "gte": "18/12/2016",
15 "lte": "now",
16 "format": "dd/MM/yyyy||yyyy"
17 }
18 }
19 }
20 ]
21 }
22 }
23 }'
Recherche dans plusieurs index identifiés, avec filtre des champs de sortie
1 curl -XGET http://127.0.0.1:9200/logstash-rproxy-2016.12.20,logstash-rproxy-2016.12.19,logstash-rproxy-2016.12.18/_search?pretty= y -d '
2 {
3 "fields" : ["URL", "user_agent","user"],
4 "query": {
5 "bool": {
6 "must": [
7 { "match": { "URL.raw": "/public" }},
8 { "match": { "application": "extranet1" }}
9 ]
10 }
11 }
12 }'