Announcing the Logz.io Search API
Logz.io has announced a new API that will enable users to safely and securely query the data that they are shipping to Logz.io using the Elasticsearch Search API DSL.
Join the DZone community and get the full member experience.
Join For Freethere’s nothing like starting a new year with new product-related announcements! in this case, i’m happy to inform our users of a new search api that will enable them to safely and securely query the data that they are shipping to logz.io using the elasticsearch search api dsl.
this api replaces the older query api, which was much more limited in scope and capabilities and will be deprecated in a few months.
why would you use the api to query elasticsearch instead of kibana? well, you could, for example, integrate with the api to create some kind of baseline for monitoring new services. as soon as a new service or host registers, you could use the api to match which of them are logging into elasticsearch.
below are some general guidelines on the api along with explanations of existing limitations and one simple example of how to use it.
licensing and limitations
for now, only our enterprise users will have access to the search api. likewise, we are currently limiting the number of search results to 10,000 (with paging).
queries can only be performed against data shipped over the prior two days (the current day and the one preceding it).
api tokens
to use the search api, you will first need to retrieve an api token. the token can be generated on the user tokens page in your account’s user settings:
using the api
once you have the token, you can begin querying your data.
first, build your query in json format in a file. you can refer to the elasticsearch search api documentation for guidance on how to build the query.
for example, i’m going to query my account for a simple string and limit the search to one response:
{
"from" : 0, "size" : 1,
"query": {
"query_string": {
"query": "canada"
}
}
}
then, build your api as follows (replace api-token with your token and query with the path to your query file):
curl -xpost 'https://api.logz.io/v1/search' --header "x-user-token: <api-token>" --header "content-type: application/json" --data-binary @<query>
and the response:
{
"hits":{
"total":984,
"max_score":5.7908382,
"hits":[
{
"_index":"logz-xmywsrkbovjddxljvcahcxsrbifbccrh-161227_v2",
"_type":"myfirewall",
"_id":"avk9li_bmfctv-i4vosg",
"_score":5.7908382,
"_source":{
"geoip":{
"timezone":"america/toronto",
"ip":"204.138.58.86",
"latitude":43.5924,
"continent_code":"na",
"city_name":"toronto",
"country_code2":"ca",
"country_name":"canada",
"country_code3":"can",
"region_name":"on",
"location":[
-79.7611,
43.5924
],
"real_region_name":"ontario",
"postal_code":"l5n",
"longitude":-79.7611
},
"message":"<2016-12-27t20:31:13z><myfw-dc2>:src_ip=204.138.58.86,sport=4209,dst_ip=87.151.247.146,dport=443",
"type":"myfirewall",
"dst_ip":"87.151.247.146",
"tags":[
"_logz_http_bulk_json_8070",
"geoip"
],
"src_ip":"204.138.58.86",
"dport":443,
"hostname":"myfw-dc2",
"@timestamp":"2016-12-27t20:31:13.000+00:00",
"sport":4209
}
}
]
}
endnotes
- be sure to use https in the request url. an http request will result in a “403” response.
- the request body needs to comply with the elasticsearch search api . there are, however, some limitations that we highly recommend you review before you begin using the api.
- more examples and documentation are available here .
we’d love to get your feedback. if you encounter any bugs, please open an issue on github or send us your comments to: support (at) logz.io.
happy querying!
Published at DZone with permission of Daniel Berman, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments