# Logstash doesn't apply my ES Template when I upload data

**URL:** https://discuss.elastic.co/t/logstash-doesnt-apply-my-es-template-when-i-upload-data/153813
**Category:** Logstash
**Created:** [October 24, 2018, 1:37pm UTC](https://discuss.elastic.co/t/logstash-doesnt-apply-my-es-template-when-i-upload-data/153813 "2018-10-24T13:37:04Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![romainrom](https://avatars.discourse-cdn.com/v4/letter/r/bbce88/32.png) [@romainrom](https://discuss.elastic.co/u/romainrom)
#### Post date: [October 24, 2018, 1:37pm UTC](https://discuss.elastic.co/t/logstash-doesnt-apply-my-es-template-when-i-upload-data/153813/1 "2018-10-24T13:37:04Z")

</div>

Hello,

I'm trying to use Logstash to load Oracle data to ES applying a specific template.  
logstash version : 6.4.2  
Here are the steps followed:

Step 1: retrieve data from Oracle and send them to ES without any template  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/5/25a0a94085bcd9dff3d3d9109537147bdc941f53.png)

Step 2 : retrieve existing mapping in one file with cURL

curl –XGET [http://localhost:9200/index9/\_mapping?pretty](http://localhost:9200/index9/_mapping?pretty) \> template9.json

Step 3 : adapt the mapping to do my template (red circled = what I’ve changed)

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/0/50d7110e2f30157d753ecdf56ba4f06cda6330ec.png)

Step 4: load the template with cURL

Curl –XPUT –H “Content-type: application/json” [http://localhost:9200/\_template/index9?pretty](http://localhost:9200/_template/index9?pretty) –d @template9.json

Acknowledged = true

Step 5: drop existing ES index with cURL

curl –XDELETE [http://localhost:9200/index9?pretty](http://localhost:9200/index9?pretty)

ack = true

Step 6: Modify my logstash-config.conf file

![image](https://us1.discourse-cdn.com/elastic/original/3X/6/b/6b4fd93a544ed52bb2b1b8e55d87717581dd445f.png)

Step 7 : launch logstash to load ES data

Logstash –f logstash.config.conf

No error detected within Logstash logs.

Step 8: results

Template looks good:

 ![2018-10-24_14h59_08](https://us1.discourse-cdn.com/elastic/original/3X/b/b/bbf80da638a801c4f6eb8d981748f67e4ce5eda2.png)

However I don’t get my “new object”,  
all data are on the same level:  
 ![2018-10-24_15h01_56](https://us1.discourse-cdn.com/elastic/original/3X/0/4/04ac9fcf76df8f72cd54a9a1d587aefef83f5f8a.png)

And the mapping seems different:

 ![2018-10-24_15h05_51](https://us1.discourse-cdn.com/elastic/original/3X/b/e/bef819c94356bdb1bdd1226d8132d1b5561ae27d.png)

Anyone know what I’m missing ?

---

<div class="post-metadata">

### Author: ![balumurari1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/balumurari1/32/39203_2.png) [@balumurari1](https://discuss.elastic.co/u/balumurari1)
#### Post date: [October 25, 2018, 7:14am UTC](https://discuss.elastic.co/t/logstash-doesnt-apply-my-es-template-when-i-upload-data/153813/2 "2018-10-25T07:14:29Z")

</div>

Hello,  
can you provide your input code, which helps to give you solution

---

<div class="post-metadata">

### Author: ![romainrom](https://avatars.discourse-cdn.com/v4/letter/r/bbce88/32.png) [@romainrom](https://discuss.elastic.co/u/romainrom)
#### Post date: [October 25, 2018, 7:24am UTC](https://discuss.elastic.co/t/logstash-doesnt-apply-my-es-template-when-i-upload-data/153813/3 "2018-10-25T07:24:07Z")

</div>

Hello !  
Thank you for your help!

Here's the input part of my logstash-config.conf:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/f/9f34ed146d2c37934c5c61543bc5a0ec763dfbd1.png)

---

<div class="post-metadata">

### Author: ![romainrom](https://avatars.discourse-cdn.com/v4/letter/r/bbce88/32.png) [@romainrom](https://discuss.elastic.co/u/romainrom)
#### Post date: [October 25, 2018, 7:25am UTC](https://discuss.elastic.co/t/logstash-doesnt-apply-my-es-template-when-i-upload-data/153813/4 "2018-10-25T07:25:05Z")

</div>

# file: logstash-config.conf

input {  
jdbc {  
# Postgres jdbc connection string to our database, mydb  
jdbc\_connection\_string =\> "jdbc:oracle:thin:@localhost:1521:DATABASE"

```
    # The user we wish to execute our statement as
    jdbc_user => "ROMAINROM"
	jdbc_password => "ROMAINROM"
	
    # The path to our jdbc driver for Oracle
    jdbc_driver_library => "xxxx\oracle-10g\ojdbc14.jar"
	
    # The name of the driver class for Oracle
    jdbc_driver_class => "Java::oracle.jdbc.driver.OracleDriver"
	
	
    # our query
    statement_filepath => "query.sql"

}

```

}  
#filter {

# json {

# source =\> "message"

# }

#}

---

<div class="post-metadata">

### Author: ![romainrom](https://avatars.discourse-cdn.com/v4/letter/r/bbce88/32.png) [@romainrom](https://discuss.elastic.co/u/romainrom)
#### Post date: [October 25, 2018, 7:27am UTC](https://discuss.elastic.co/t/logstash-doesnt-apply-my-es-template-when-i-upload-data/153813/5 "2018-10-25T07:27:42Z")

</div>

Sorry about the presentation 🙂 ,  
no filter applied.

---

<div class="post-metadata">

### Author: ![balumurari1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/balumurari1/32/39203_2.png) [@balumurari1](https://discuss.elastic.co/u/balumurari1)
#### Post date: [October 25, 2018, 7:30am UTC](https://discuss.elastic.co/t/logstash-doesnt-apply-my-es-template-when-i-upload-data/153813/6 "2018-10-25T07:30:56Z")

</div>

The input code is fine, in the output did you mention elasticsearch to get the result,

Try this,

input {

jdbc {  
jdbc\_driver\_library =\> "xxxx\oracle-10g\ojdbc14.jar"  
jdbc\_driver\_class =\> "oracle.jdbc.driver.OracleDriver"  
jdbc\_connection\_string =\> "jdbc:oracle:thin:@localhost:1521:DATABASE"  
jdbc\_user =\> "ROMAINROM"  
jdbc\_password =\> "ROMAINROM"  
statement =\> "SELECT TOP 10 \* FROM TABLE"  
jdbc\_paging\_enabled =\> "true"  
jdbc\_page\_size =\> "50000"  
}

}

output{  
elasticsearch { codec =\> json hosts =\> ["localhost:9200"] index =\> "index9" }  
stdout { codec =\> rubydebug }  
}

---

<div class="post-metadata">

### Author: ![romainrom](https://avatars.discourse-cdn.com/v4/letter/r/bbce88/32.png) [@romainrom](https://discuss.elastic.co/u/romainrom)
#### Post date: [October 25, 2018, 8:26am UTC](https://discuss.elastic.co/t/logstash-doesnt-apply-my-es-template-when-i-upload-data/153813/7 "2018-10-25T08:26:51Z")

</div>

Well actually I got the output in ES  
but ES data are not mapped according to my template...

I add like you said:   
jdbc\_paging\_enabled =\> "true"  
jdbc\_page\_size =\> "50000"

I haven't modified my query as it's an inner join that worked so far.

And tried both output (I deleted index9 before each test):

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/b/5/b549b84e6597918090a9e6a67bc4ba0a583cd975.png)  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/a/9aee7883f2467f2a6e7cc6a98b8b93c270e42b0a.png)

I have still the same issue:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/3/230c1bbb57023e44e24f4072083e0e138713f329.png)  
Template is not applied...

---

<div class="post-metadata">

### Author: ![balumurari1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/balumurari1/32/39203_2.png) [@balumurari1](https://discuss.elastic.co/u/balumurari1)
#### Post date: [October 25, 2018, 10:52am UTC](https://discuss.elastic.co/t/logstash-doesnt-apply-my-es-template-when-i-upload-data/153813/8 "2018-10-25T10:52:05Z")

</div>

You need to check with the query whether it is retrieving correct data from database or not. Please verify once.

---

<div class="post-metadata">

### Author: ![romainrom](https://avatars.discourse-cdn.com/v4/letter/r/bbce88/32.png) [@romainrom](https://discuss.elastic.co/u/romainrom)
#### Post date: [October 25, 2018, 12:16pm UTC](https://discuss.elastic.co/t/logstash-doesnt-apply-my-es-template-when-i-upload-data/153813/9 "2018-10-25T12:16:42Z")

</div>

My query looks like:  
SELECT  
TABLE1.CSAGUID,TABLE1.TYPE\_FATHER,TABLE1.NBFILS,  
TABLE2.PRIORITY,TABLE2.DISPLAY  
FROM TABLE1  
INNER JOIN TABLE2  
ON TABLE1.FATHER\_GUID=TABLE2.CSAGUID

This query gives 96 lines in Oracle DB and I also retrieve these 96 hits in ES DB,  
all values seem correct so far.

So I think this query is correct.

---

<div class="post-metadata">

### Author: ![balumurari1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/balumurari1/32/39203_2.png) [@balumurari1](https://discuss.elastic.co/u/balumurari1)
#### Post date: [October 25, 2018, 12:21pm UTC](https://discuss.elastic.co/t/logstash-doesnt-apply-my-es-template-when-i-upload-data/153813/10 "2018-10-25T12:21:27Z")

</div>

can you display the output of this query,

[http://localhost:9200/index9/\_search](http://localhost:9200/index9/_search)

---

<div class="post-metadata">

### Author: ![romainrom](https://avatars.discourse-cdn.com/v4/letter/r/bbce88/32.png) [@romainrom](https://discuss.elastic.co/u/romainrom)
#### Post date: [October 25, 2018, 12:32pm UTC](https://discuss.elastic.co/t/logstash-doesnt-apply-my-es-template-when-i-upload-data/153813/11 "2018-10-25T12:32:34Z")

</div>

yes, I get:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/c/b/cb671d30cd2b7c610ebde9f11d82ecb12a126a76.png)

---

<div class="post-metadata">

### Author: ![balumurari1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/balumurari1/32/39203_2.png) [@balumurari1](https://discuss.elastic.co/u/balumurari1)
#### Post date: [October 25, 2018, 12:36pm UTC](https://discuss.elastic.co/t/logstash-doesnt-apply-my-es-template-when-i-upload-data/153813/12 "2018-10-25T12:36:32Z")

</div>

ok now can you please tell me what is the output you were expecting to be displayed

---

<div class="post-metadata">

### Author: ![romainrom](https://avatars.discourse-cdn.com/v4/letter/r/bbce88/32.png) [@romainrom](https://discuss.elastic.co/u/romainrom)
#### Post date: [October 25, 2018, 2:00pm UTC](https://discuss.elastic.co/t/logstash-doesnt-apply-my-es-template-when-i-upload-data/153813/13 "2018-10-25T14:00:12Z")

</div>

yes, like described in step 3 and step 8 above, I want to get the following template applied :

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/f/7f3904abbb6be60c7e4d41db80823c66ceface3b.png)

Unfortunately I do not get the "newobject" level...

---

<div class="post-metadata">

### Author: ![romainrom](https://avatars.discourse-cdn.com/v4/letter/r/bbce88/32.png) [@romainrom](https://discuss.elastic.co/u/romainrom)
#### Post date: [October 26, 2018, 1:51pm UTC](https://discuss.elastic.co/t/logstash-doesnt-apply-my-es-template-when-i-upload-data/153813/14 "2018-10-26T13:51:32Z")

</div>

Any ideas?

---

<div class="post-metadata">

### Author: ![romainrom](https://avatars.discourse-cdn.com/v4/letter/r/bbce88/32.png) [@romainrom](https://discuss.elastic.co/u/romainrom)
#### Post date: [October 30, 2018, 7:49am UTC](https://discuss.elastic.co/t/logstash-doesnt-apply-my-es-template-when-i-upload-data/153813/15 "2018-10-30T07:49:29Z")

</div>

Ok, I finally found a collleague of mine who told me that he had the same issue 2 years ago, so I give up templates with a logstash loading in ES...  
I'm going to use the mutate option then.

---

<div class="post-metadata">

### Author: ![romainrom](https://avatars.discourse-cdn.com/v4/letter/r/bbce88/32.png) [@romainrom](https://discuss.elastic.co/u/romainrom)
#### Post date: [October 30, 2018, 7:50am UTC](https://discuss.elastic.co/t/logstash-doesnt-apply-my-es-template-when-i-upload-data/153813/16 "2018-10-30T07:50:05Z")

</div>

And a script to read the data.

---

<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: [November 27, 2018, 7:50am UTC](https://discuss.elastic.co/t/logstash-doesnt-apply-my-es-template-when-i-upload-data/153813/17 "2018-11-27T07:50:10Z")

</div>

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