# Merge or combine two indexes to one based on common field (id)

**URL:** <https://discuss.elastic.co/t/merge-or-combine-two-indexes-to-one-based-on-common-field-id/178678>\
**Category:** Logstash\
**Created:** [April 26, 2019, 3:36pm UTC](https://discuss.elastic.co/t/merge-or-combine-two-indexes-to-one-based-on-common-field-id/178678 "2019-04-26T15:36:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![aldol](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@aldol](https://discuss.elastic.co/u/aldol)\
**Post date:** [April 26, 2019, 3:36pm UTC](https://discuss.elastic.co/t/merge-or-combine-two-indexes-to-one-based-on-common-field-id/178678/1 "2019-04-26T15:36:17Z")

</div>

I have one index (index1) with columns "name" and "id" and the other index (index2) with columns "resume" and "id".  
"id" is the common field between two indexes.  
How can I merge or combine them together so I get one index (index3) with columns "name", "resume", "id".  
When I say combine, it means if I have data in index1 as  
"name": "Mike"  
"id": 123  
and I have data in index 2 as  
"resume": "looks for ...bla bla bla.."  
"id": 123

This is what I want in index 3 as a result of combining index1 and index2:  
index3:  
"name": "Mike"  
"id": 123  
"resume": "looks for ...bla bla bla.."

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [April 26, 2019, 7:20pm UTC](https://discuss.elastic.co/t/merge-or-combine-two-indexes-to-one-based-on-common-field-id/178678/2 "2019-04-26T19:20:20Z")

</div>

I think you can use input filter named elasticsearch  
[https://www.elastic.co/guide/en/logstash/current/plugins-inputs-elasticsearch.html](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-elasticsearch.html)

use two input filter,  
and then output on elasticsearch with new index name

---

<div class="post-metadata">

**Author:** ![aldol](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@aldol](https://discuss.elastic.co/u/aldol)\
**Post date:** [April 27, 2019, 11:29pm UTC](https://discuss.elastic.co/t/merge-or-combine-two-indexes-to-one-based-on-common-field-id/178678/3 "2019-04-27T23:29:47Z")

</div>

I am using the following configuration but I am getting "connection refused" error:  
input {  
elasticsearch {  
hosts =\> "localhost"  
user =\> "abc"  
password =\> "abc1"  
index =\> "twitter1"  
size =\> 500  
scroll =\> "5m"  
docinfo =\> true  
}  
}  
output {  
elasticsearch {  
document\_id =\> "%{[@metadata][\_id]}"  
hosts =\> "localhost"  
ssl\_certificate\_verification =\> "true"  
index =\> "twitter3"  
user =\> "abc"  
password =\> "abc1"  
}  
}  
I think the issue is "hosts" in elasticsearch in input, but I don't know what to put there.

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [May 6, 2019, 7:29pm UTC](https://discuss.elastic.co/t/merge-or-combine-two-indexes-to-one-based-on-common-field-id/178678/4 "2019-05-06T19:29:44Z")

</div>

Hi did you fixed this issue  
I think you should have  
input {  
elasticsearch {  
hosts =\> ["hostname:9200"]  
index =\> "index\_name"  
}  
}

---

<div class="post-metadata">

**Author:** ![aldol](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@aldol](https://discuss.elastic.co/u/aldol)\
**Post date:** [May 20, 2019, 3:18pm UTC](https://discuss.elastic.co/t/merge-or-combine-two-indexes-to-one-based-on-common-field-id/178678/5 "2019-05-20T15:18:53Z")

</div>

I tried. It didn't work. I am getting error:  
"Failed to open TCP connection to hostname:9200 (initialize: name or service not known)"

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [May 20, 2019, 3:30pm UTC](https://discuss.elastic.co/t/merge-or-combine-two-indexes-to-one-based-on-common-field-id/178678/6 "2019-05-20T15:30:25Z")

</div>

is your elasticsearch reading via name or localhost.  
what is output of following from your system

# curl hostname:9200/\_cluster/health?pretty

---

<div class="post-metadata">

**Author:** ![aldol](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@aldol](https://discuss.elastic.co/u/aldol)\
**Post date:** [May 20, 2019, 7:08pm UTC](https://discuss.elastic.co/t/merge-or-combine-two-indexes-to-one-based-on-common-field-id/178678/7 "2019-05-20T19:08:36Z")

</div>

The problem was certificate. Now it is working. Thank you for the follow up.

---

<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:** [June 17, 2019, 7:08pm UTC](https://discuss.elastic.co/t/merge-or-combine-two-indexes-to-one-based-on-common-field-id/178678/8 "2019-06-17T19:08:44Z")

</div>

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