# How to use \_sql (SQL queries) to access Elasticsearch indexes in Logstash input plugin

**URL:** https://discuss.elastic.co/t/how-to-use-sql-sql-queries-to-access-elasticsearch-indexes-in-logstash-input-plugin/265327
**Category:** Logstash
**Created:** [February 24, 2021, 11:18am UTC](https://discuss.elastic.co/t/how-to-use-sql-sql-queries-to-access-elasticsearch-indexes-in-logstash-input-plugin/265327 "2021-02-24T11:18:02Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Amit\_Singh4](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amit_singh4/32/84459_2.png) [@Amit\_Singh4](https://discuss.elastic.co/u/Amit_Singh4)
#### Post date: [February 24, 2021, 11:18am UTC](https://discuss.elastic.co/t/how-to-use-sql-sql-queries-to-access-elasticsearch-indexes-in-logstash-input-plugin/265327/1 "2021-02-24T11:18:02Z")

</div>

Hi  
I want to use \_sql (SQL queries) to access Elasticsearch indexes in Logstash input plugin. Find my logstash config as below:

input {  
http\_poller {  
urls =\> {  
test1 =\> {  
method =\> "POST"  
user =\> "abc"  
password =\> "xyz"  
url =\> "http:// **.**.\*\*.123:9200/\_sql?format=txt"  
body =\> '{  
"query": "SELECT id, name FROM testindex"  
}'  
}  
}  
request\_timeout =\> 60  
codec =\> "json"  
metadata\_target =\> "http\_poller\_metadata"  
}  
}

output {  
#stdout {}

elasticsearch {  
hosts =\> ["http:// **.**.\*\*.123:9200"]  
user =\> "abc"  
password =\> "xyz"  
index =\> "testDest"  
}  
}

This is not working when starting logstash and giving below error:  
message=\>"Unable to configure plugins: (ConfigurationError) Something is wrong with your configuration.", :backtrace=\>["org.logstash.config.ir.CompiledPipeline.

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [February 24, 2021, 2:31pm UTC](https://discuss.elastic.co/t/how-to-use-sql-sql-queries-to-access-elasticsearch-indexes-in-logstash-input-plugin/265327/2 "2021-02-24T14:31:12Z")

</div>

> [@Amit\_Singh4](#):
>
> This is not working when starting logstash and giving below error:  
> message=\>"Unable to configure plugins: (ConfigurationError) Something is wrong with your configuration."

There should be a more specific error from the plugin that says what is wrong with the configuration.

---

<div class="post-metadata">

### Author: ![Amit\_Singh4](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amit_singh4/32/84459_2.png) [@Amit\_Singh4](https://discuss.elastic.co/u/Amit_Singh4)
#### Post date: [February 25, 2021, 5:17am UTC](https://discuss.elastic.co/t/how-to-use-sql-sql-queries-to-access-elasticsearch-indexes-in-logstash-input-plugin/265327/3 "2021-02-25T05:17:46Z")

</div>

Update Config and Error:

input {  
http\_poller {  
urls =\> {  
test1 =\> {  
method =\> "POST"  
user =\> "abc"  
password =\> "xyz"  
url =\> "http://..\*\*.123:9200/\_sql?format=txt"  
body =\> '{"query": "SELECT id, name FROM testindex"}'  
headers =\> {Accept =\> "application/json"}  
}  
}  
request\_timeout =\> 60  
schedule =\> { cron =\> "\* \* \* \* \* UTC"}  
codec =\> "json"  
metadata\_target =\> "http\_poller\_metadata"  
}  
}

output {  
#stdout {}

elasticsearch {  
hosts =\> ["http://..\*\*.123:9200"]  
user =\> "abc"  
password =\> "xyz"  
index =\> "testDest"  
}  
}

Error:---\>

[2021-02-25T10:45:57,893][INFO][logstash.javapipeline][main] Pipeline started {"pipeline.id"=\>"main"}  
[2021-02-25T10:45:57,973][INFO][logstash.agent] Pipelines running {:count=\>1, :running\_pipelines=\>[:main], :non\_running\_pipelines=\>}  
[2021-02-25T10:45:58,479][INFO][logstash.agent] Successfully started Logstash API endpoint {:port=\>9600}  
C:/logstash/vendor/bundle/jruby/2.5.0/gems/rufus-scheduler-3.0.9/lib/rufus/scheduler/cronline.rb:77: warning: constant ::Fixnum is deprecated  
{  
"error" =\> "Content-Type header [text/plain; charset=ISO-8859-1] is not supported",  
"status" =\> 406,  
"@version" =\> "1",  
"@timestamp" =\> 2021-02-25T05:16:00.481Z,  
"http\_poller\_metadata" =\> {  
"host" =\> "IN-ABCD",  
"request" =\> {  
"auth" =\> {  
"user" =\> "abc",  
"eager" =\> true,  
"pass" =\> "xyz"  
},  
"method" =\> "post",  
"url" =\> "http://_._._._:9200/\_sql?format=txt",  
"body" =\> "{"query": "SELECT \* FROM rpalogpoc"}",  
"headers" =\> {  
"Accept" =\> "application/json"  
}  
},  
"response\_message" =\> "Not Acceptable",  
"response\_headers" =\> {  
"content-type" =\> "application/json; charset=UTF-8"  
},  
"name" =\> "test1",  
"runtime\_seconds" =\> 0.204,  
"times\_retried" =\> 0,  
"code" =\> 406  
}  
}

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [February 25, 2021, 4:41pm UTC](https://discuss.elastic.co/t/how-to-use-sql-sql-queries-to-access-elasticsearch-indexes-in-logstash-input-plugin/265327/4 "2021-02-25T16:41:53Z")

</div>

> [@Amit\_Singh4](#):
>
> "error" =\> "Content-Type header [text/plain; charset=ISO-8859-1] is not supported",

You should set a content-type header on the request.

---

<div class="post-metadata">

### Author: ![Amit\_Singh4](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amit_singh4/32/84459_2.png) [@Amit\_Singh4](https://discuss.elastic.co/u/Amit_Singh4)
#### Post date: [March 3, 2021, 6:08am UTC](https://discuss.elastic.co/t/how-to-use-sql-sql-queries-to-access-elasticsearch-indexes-in-logstash-input-plugin/265327/5 "2021-03-03T06:08:07Z")

</div>

@Badger , if you see the update config, its already set in request:  
headers =\> {Accept =\> "application/json"}

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [March 31, 2021, 6:08am UTC](https://discuss.elastic.co/t/how-to-use-sql-sql-queries-to-access-elasticsearch-indexes-in-logstash-input-plugin/265327/6 "2021-03-31T06:08:20Z")

</div>

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