Curl access to elasticsearch


(Chenzilong444) #1

C:\Users>curl -H "Content-Type: application/json" -XGET "http://local
host:9200/logstash-pc-(2018-05-09)/_search?pretty" -d "{"query":{"match":{"MSG":
"Test3"}}}"
{
"error" : {
"root_cause" : [
{
"type" : "json_parse_exception",
"reason" : "Unexpected character ('q' (code 113)): was expecting double-
quote to start field name\n at [Source: org.elasticsearch.transport.netty4.ByteB
ufStreamInput@3c8ad001; line: 1, column: 3]"
}
],
"type" : "json_parse_exception",
"reason" : "Unexpected character ('q' (code 113)): was expecting double-quot
e to start field name\n at [Source: org.elasticsearch.transport.netty4.ByteBufSt
reamInput@3c8ad001; line: 1, column: 3]"
},
"status" : 500
}
i want to know how to write query


(David Pilato) #2

May be:

curl -H "Content-Type: application/json" -XGET "http://local
host:9200/logstash-pc-(2018-05-09)/_search?pretty" -d '{"query":{"match":{"MSG":
"Test3"}}}'

(Chenzilong444) #3

it can't work when i use ‘
C:\Users\chenzilong>curl -H "Content-Type: application/json" -X GET "http://localhost:9200/logstash-pc(2018-05-09)/_search?pretty" -d '{"query":{"match":{"MSG": "Test3"}}}'

{
"error" : {
"root_cause" : [
{
"type" : "json_parse_exception",
"reason" : "Unexpected character (''' (code 39)): expected a valid value
(number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.el
asticsearch.transport.netty4.ByteBufStreamInput@4a5f25fd; line: 1, column: 2]"
}
],
"type" : "json_parse_exception",
"reason" : "Unexpected character (''' (code 39)): expected a valid value (nu
mber, String, array, object, 'true', 'false' or 'null')\n at [Source: org.elasti
csearch.transport.netty4.ByteBufStreamInput@4a5f25fd; line: 1, column: 2]"
},
"status" : 500
}


(Val Crettaz) #4

On Windows, the command prompt doesn't support single quotes, use " and escape the inner ones with \".

curl -H "Content-Type: application/json" -XGET "http://localhost:9200/logstash-pc-(2018-05-09)/_search?pretty" -d "{\"query\":{\"match\":{\"MSG\":\"Test3\"}}}"

(Chenzilong444) #5

thank you. it work .i have never know that thing


(Val Crettaz) #6

Cool, great it helped!


(David Pilato) #7

I'd also suggest using Kibana dev console which makes all that easier.


(system) #8

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.