How to create visualization from data inside a hit in kibana? - elasticsearch

I am looking to create dashboard in kibana using the data from the postgresql database. But the datas are shown up in the same hit in kibana, so can't able to create the visualization.
I would like to create visualization in kibana from the data I had fetched from postgresql. I need to create visualization by comparing the datas inside single column in postgresql. But in kibana, the data in single column of postgresql is showing in the single hit of kibana. So, I am unable to create the visualization from this single hit data. If there is any way to filter the data inside a hit in kibana or to check the word count in single hit?

To find the number of "FAILED" you need to use match query in Kibana like:
GET <YOUR_INDEX>/_count
{
"query": {
"bool": {
"must": {
"match": {
"<YOUR_FIELD>": "FAILED"
}
}
}
}
}
or if you have many fields:
GET <YOUR_INDEX>/_count
{
"query": {
"multi_match" : {
"query": "FAILED",
"fields": [ "<FIELD1>", "<FIELD2>" ]
}
}
}

Related

How to delete a test record from elastic search

I've been testing my website and notice the elastic search has indexed those test records.
My Question, how can I query elasticsearch to delete the test record?
Just issue a HTTP POST in the following model :
POST /{index/_delete_by_query
{
"query": {
"match": {
"field": "value"
}
}
}

Elasticsearch delete By Query not completing deletes

I need to delete a large number of documents in a 5.5 Elasticsearch cluster. I know the optimal way to do this is to rebuild the cluster without the intended documents, but that's not possible in our case. I run the following query that deletes documents from a subset of the indexes in the cluster:
GET myindex_1*/doc_type/_delete_by_query
{
"query": {
"bool": {
"filter": [
{
"terms": {
"typeCode": [
"Filtered_Type"
]
}
}
],
"must": [
{
"range": {
"createdDateUTC": {
"lt": "2017-10-28"
}
}
}
]
}
}
}
It starts deleting documents for a couple of hours but then just stops and I have to kick it off again. Any ideas why it stops running the delete query?
Just a note, I'm using Kibana to run the query and the request times out on the client side when though I can see it continues deleting on the backend.
From here:
By default _delete_by_query uses scroll batches of 1000. You can change the batch size with the scroll_size URL parameter:
POST twitter/_delete_by_query?scroll_size=5000
{
"query": {
"term": {
"user": "kimchy"
}
}
}
You can find more information here about batching and batch sizes here:
batches and requests_per_second in ElasticSearch Delete By Query API
And since you'll need to scroll through one to many batches to delete all of the documents found by your query, you can find more information about scrolling here:
https://www.elastic.co/guide/en/elasticsearch/reference/5.5/search-request-scroll.html

How to use DSL query from Kibana dev-tools in visualisation?

I have successfully aggregated and queried a particular content I needed in Kibana Dev Tools. However, I need this information in a tabular form either as CSV or PDF. For this, I need to run the DSL query I constructed in Dev Tools in visualisation tool of Kibana. However, I am not able to do it.
I tried copying the DSL to the Lucene query text box on the top part of the visualisation page and also tried within the add filter option. Both way it returns an error.
The query that works in Dev Tools:
{
"query": {
"bool": {
"must": [
{ "match": { "start_datetime":"1569868200" }}
]
}
},
"aggs" : {
"state_location" : {
"terms": {
"field" : "state_location"
},
"aggs": {
"stakeholder_category": {
"terms": {
"field": "stakeholder_category"
},
"aggs": {
"coverage_category": {
"terms": {
"field": "category_paragraph_name.keyword"
}
}
}
}
}
}
}
}
Expecting to get the result on visualisation screen as a table, so that I can export it to CSV or PDF.
The search bar in the discovery bar doesn't work with the json-syntax of a search request towards the REST-API. Instead it uses a simple lucene syntax.
However, you still can edit your search in the discovery manually:
You should be able to see a button with the label "Inspect" like in the following figure.
Note that the look & feel of Kibana got a significant update, so depending of the version you are using, you will find the Inspect button somewhere else in the discovery)
By hitting the button, a right-sided pane will show up with three tabs (Statistics, Request and Response). In the Request-section you can paste your query. Be sure NOT to past the root "query"-node of your json.
Hope, this will help you :-)

how to log or print python elasticsearch-dsl query that gets invoked

I am using elasticsearch-dsl for my python application to query elastic search.
To debug what query is actually getting generated by elasticsearch-dsl library, I am unable to log or print the final query that goes to elasticsearch.
For example, like to see the request body sent to elasticsearch like this :
{
"query": {
"query_string": {
"query": "Dav*",
"fields": ["name", "short_code"],
"analyze_wildcard": true
}
}
}
Tried to bring the elasticsearch log level to TRACE. Even then, unable to see the queries that got executed.
Take a look at my blog post here, "Slowlog settings at index level" section. Basically, you can use slowlog to print in a separate log file Elasticsearch generates, the queries. I suggest using a very low threshold to be able to see all the queries.
For example, something like this, for a specific index:
PUT /test_index/_settings
{
"index": {
"search.slowlog.level": "trace",
"search.slowlog.threshold.query.trace": "1ms"
}
}
Or
PUT /_settings
{
"index": {
"search.slowlog.level": "trace",
"search.slowlog.threshold.query.trace": "1ms"
}
}
as a cluster-wide setting, for all the indices.
And the queries will be logged in your /logs location, a file called [CLUSTER_NAME]_index_search_slowlog.log.

Return list of affected indices from in Elasticsearch

I need to write a query which will search across all indices in Elastisearch and return me a list of all indices where at least one document meets query requirements.
For now I`m getting top 2000 documents and distinct them by index name.
To search across all indices in the elastcsearch, you can use the _all option.
You can try similar to following, to get the indices which gets hits for the query
POST _all/_search
{
"query": {
"filtered": {
"query": {
"query_string": {
"query": "you search criteia"
}
}
}
}
}
Most APIs that refer to an index parameter support execution across multiple indices, using simple test1,test2,test3 notation (or _all for all indices)
You can extract the index name from the result set which will be present under _index
sample result:
"hits": [
{
"_index": "index-name",
}
]

Resources