# Merge different index in function two fields and paste eleement of fields

**URL:** https://discuss.elastic.co/t/merge-different-index-in-function-two-fields-and-paste-eleement-of-fields/293363
**Category:** Elasticsearch
**Created:** [January 3, 2022, 3:35pm UTC](https://discuss.elastic.co/t/merge-different-index-in-function-two-fields-and-paste-eleement-of-fields/293363 "2022-01-03T15:35:37Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Vivian](https://avatars.discourse-cdn.com/v4/letter/v/3e96dc/32.png) [@Vivian](https://discuss.elastic.co/u/Vivian)
#### Post date: [January 3, 2022, 3:35pm UTC](https://discuss.elastic.co/t/merge-different-index-in-function-two-fields-and-paste-eleement-of-fields/293363/1 "2022-01-03T15:35:37Z")

</div>

Hello, I have an index of this shape :

```auto
{
  "_index": "df_extrait",
  "_type": "_doc",
  "_id": "27685",
  "_version": 1,
  "_seq_no": 0,
  "_primary_term": 1,
  "_score": 1,
  "_source": {
    "source": "avatar",
    "target": "toutpublic",
    "confidence_Score": "-",
    "Ref": "10716926",
    "Databases": "OCS:1234",
    "Taxon": "Film",
    "Interaction_Method": "Dialogue",
    "ID_method": ["M0004"],
    "Source_film": "OCS"
  }
}

{
  "_index": "df_extrait",
  "_type": "_doc",
  "_id": "82335",
  "_version": 1,
  "_seq_no": 10,
  "_primary_term": 1,
  "_score": 1,
  "_source": {
    "Source_film": "TF1Studio",
    "source": "avatar",
    "target": "toutpublic",
    "Taxon": "Film",
    "Ref": [
      "20936779",
      "10716926",
      "12970366",
      "32203420"
    ],
    "ID_method": [
      "M0398",
      "M0428",
      "M0096",
      "M0019",
      "M0018",
      "M0059",
      "M0045",
      "M0004",
      "M0004",
      "M0007"
    ],
    "Interaction_Method": [
      "Projection interactive",
      "Animation",
      "Animation virtuelle",
      "Modelage",
      "Projection anime",
      "Fond vert",
      "Extraction paysage",
      "Dialogue",
      "Dialogue",
      "Fond rouge"
    ]
  }
}

```

I would like to reunite the different index according to the source and target fields and create a new index in this case acquiere only one index :  
expected results in this cases :

```auto
{
  "_index": "new_index",
  "_type": "_doc",
  "_id": "82335",
  "_version": 1,
  "_seq_no": 10,
  "_primary_term": 1,
  "_score": 1,
  "_source": {
    "Source_film": ["OCS,"TF1Studio"]
    "source": "avatar",
    "target": "toutpublic",
    "Taxon": "Film",
    "Ref": [
      "20936779",
      "10716926",
      "12970366",
      "32203420"
    ],
    "ID_method": [
      "M0398",
      "M0428",
      "M0096",
      "M0019",
      "M0018",
      "M0059",
      "M0045",
      "M0004",
      "M0007"
    ],
    "Interaction_Method": [
      "Projection interactive",
      "Animation",
      "Animation virtuelle",
      "Modelage",
      "Projection anime",
      "Fond vert",
      "Extraction paysage",
      "Dialogue",
      "Fond rouge"
    ]
  }
}

```

I tried to do by aggregation or by reindexation but I fall back on my starting index, can you help me.  
Thanks for you help,  
Vivian Robin

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [January 4, 2022, 5:48am UTC](https://discuss.elastic.co/t/merge-different-index-in-function-two-fields-and-paste-eleement-of-fields/293363/2 "2022-01-04T05:48:20Z")

</div>

Elasticsearch doesn't use columns or rows, so it'd be worth changing the way you think/talk about data structures when using it, so no one is confused 🙂

I can't see a target field in your documents though?

---

<div class="post-metadata">

### Author: ![Vivian](https://avatars.discourse-cdn.com/v4/letter/v/3e96dc/32.png) [@Vivian](https://discuss.elastic.co/u/Vivian)
#### Post date: [January 4, 2022, 12:42pm UTC](https://discuss.elastic.co/t/merge-different-index-in-function-two-fields-and-paste-eleement-of-fields/293363/3 "2022-01-04T12:42:27Z")

</div>

I have modified the target field (previously called "cible") and the post for a better understanding as a beginner in devtools and Elasticsearch, please excuse me for my bad vocabulary

---

<div class="post-metadata">

### Author: ![can.ozdemir](https://avatars.discourse-cdn.com/v4/letter/c/898d66/32.png) [@can.ozdemir](https://discuss.elastic.co/u/can.ozdemir)
#### Post date: [January 4, 2022, 12:51pm UTC](https://discuss.elastic.co/t/merge-different-index-in-function-two-fields-and-paste-eleement-of-fields/293363/4 "2022-01-04T12:51:23Z")

</div>

I cannot understand the requirement clearly but, I think you want to merge two indexes using a field to match the documents. if thats the case you can check;

[https://stackoverflow.com/q/69044453/15799164](https://stackoverflow.com/q/69044453/15799164)

---

<div class="post-metadata">

### Author: ![Vivian](https://avatars.discourse-cdn.com/v4/letter/v/3e96dc/32.png) [@Vivian](https://discuss.elastic.co/u/Vivian)
#### Post date: [January 4, 2022, 2:54pm UTC](https://discuss.elastic.co/t/merge-different-index-in-function-two-fields-and-paste-eleement-of-fields/293363/5 "2022-01-04T14:54:43Z")

</div>

That's the idea and to eliminate redundant information I am inspired by this post ([Merging documents based on matched fields values](https://discuss.elastic.co/t/merging-documents-based-on-matched-fields-values/249728) , , I work on siren investigate, I managed to make my aggregation as below :

```auto
GET df_extrait/_search?size=0
{
"aggs": {
    "my composite": {
      "composite": {
        "sources": [
          {
            "source_principal": {
              "terms": {
                "field": "source.keyword"
              }
            }
          },
          {
            "target_principal": {
              "terms": {
                "field": "target.keyword"
              }
            }
          }
        ]
        
      }
    }
  }

```

When I try to create a new index in this way I get this error:

 ![Screenshot from 2022-01-04 09-53-48](https://us1.discourse-cdn.com/elastic/original/3X/2/a/2a68518512934d99c517f9fd42797c575985d7cb.png)

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [January 4, 2022, 6:12pm UTC](https://discuss.elastic.co/t/merge-different-index-in-function-two-fields-and-paste-eleement-of-fields/293363/6 "2022-01-04T18:12:43Z")

</div>

Please don't post pictures of text, logs or code. They are difficult to read, impossible to search and replicate (if it's code), and some people may not be even able to see them 🙂

---

<div class="post-metadata">

### Author: ![Vivian](https://avatars.discourse-cdn.com/v4/letter/v/3e96dc/32.png) [@Vivian](https://discuss.elastic.co/u/Vivian)
#### Post date: [January 4, 2022, 6:35pm UTC](https://discuss.elastic.co/t/merge-different-index-in-function-two-fields-and-paste-eleement-of-fields/293363/7 "2022-01-04T18:35:05Z")

</div>

As a replacement for the image:

```auto
PUT _transform/data_log
{
  "source": {
    "index": "df_extrait"
  },
  "dest": {
    "index": "df_extrait_reduced"
  },
  "pivot": {
    "group_by": {
      "source_principal": {"terms": {"field": "source"}},
      "target_principal": {"terms": {"field": "target"}}
    },
    "aggs": {
    "my composite": {
      "composite": {
        "sources": [
          {
            "source_principal": {
              "terms": {
                "field": "source.keyword"
              }
            }
          },
          {
            "target_principal": {
              "terms": {
                "field": "target.keyword"
              }
            }
          }
        ]
      }
        
      }
    }
  }
}

```

Output:

```auto
{
  "error": "Incorrect HTTP method for uri [/_transform/data_log?pretty] and method [PUT], allowed: [POST]",
  "status": 405
}

```

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [January 4, 2022, 6:51pm UTC](https://discuss.elastic.co/t/merge-different-index-in-function-two-fields-and-paste-eleement-of-fields/293363/8 "2022-01-04T18:51:57Z")

</div>

> [@Vivian](#):
>
> ```auto
> PUT _transform/data_log
> 
> ```

That doesn't match the error though, so try removing the `?pretty`.

---

<div class="post-metadata">

### Author: ![Vivian](https://avatars.discourse-cdn.com/v4/letter/v/3e96dc/32.png) [@Vivian](https://discuss.elastic.co/u/Vivian)
#### Post date: [January 4, 2022, 7:06pm UTC](https://discuss.elastic.co/t/merge-different-index-in-function-two-fields-and-paste-eleement-of-fields/293363/9 "2022-01-04T19:06:46Z")

</div>

In my request there is no pretty ` PUT _transform/data_log` is this due to the fact that siren investigate the dev-tools do not have ` _transform` ?

---

<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: [February 1, 2022, 7:07pm UTC](https://discuss.elastic.co/t/merge-different-index-in-function-two-fields-and-paste-eleement-of-fields/293363/10 "2022-02-01T19:07:26Z")

</div>

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