# Mapping\_data with 2 index

**URL:** <https://discuss.elastic.co/t/mapping-data-with-2-index/300495>\
**Category:** Elasticsearch\
**Created:** [March 23, 2022, 6:37pm UTC](https://discuss.elastic.co/t/mapping-data-with-2-index/300495 "2022-03-23T18:37:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wdffw](https://avatars.discourse-cdn.com/v4/letter/w/7993a0/32.png) [@wdffw](https://discuss.elastic.co/u/wdffw)\
**Post date:** [March 23, 2022, 6:37pm UTC](https://discuss.elastic.co/t/mapping-data-with-2-index/300495/1 "2022-03-23T18:37:05Z")

</div>

Hello,

I have a question about kibana and any help is welcome, I'm stuck on this for a week.  
I have two indexes (index1 and index2 let's say) and I want to create a mapping in index1 which has as name change and whose value must be good or not good depending on the script:

The script looks for an ip in index1, if there is a match in the ipAdress of index2, if yes it returns "match" otherwise it is "no match".

So I would like to know how to build this mapping on kinana to make this match or it's another method that will do it, what is it.

I attach the mapping below for more clarity. Thanks in advance

```auto
index1/_doc
{
  "ip": "192.168.1.1",
  "country": "Canada",
  "city": "Montreal"
}

 index2/
{
{
  "ipAdress": "192.168.1.1"
},
{
  "ipAdress": "192.168.1.1"  
}
{
  "ipAdress": "192.168.1.1"  
}}

PUT index1/_mapping
{
  "runtime": {
    "match": { 
      "type": "keyword",
        "target_index": "index2", 
        "input_field": "ip", 
        "target_field": "ipAdress"
          "script": """
         def D = all doc['ipAdress.keyword'].value 
        def val = doc['ip.keyword'].value;
        for (int i=0; i < D.length; i++){
          if ( val == D[i] ) return emit("match');}
        return emit('Not match')
      
        """
    }
  },
  "fields": ["match"]
}
}

```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [March 24, 2022, 8:19am UTC](https://discuss.elastic.co/t/mapping-data-with-2-index/300495/2 "2022-03-24T08:19:22Z")

</div>

There will be support for runtime lookup fields in Elasticsearch 8.2.0 onwards. See [https://github.com/elastic/elasticsearch/pull/82385](https://github.com/elastic/elasticsearch/pull/82385)

Is. this what you are referring to or where is the above code snippet from?

---

<div class="post-metadata">

**Author:** ![wdffw](https://avatars.discourse-cdn.com/v4/letter/w/7993a0/32.png) [@wdffw](https://discuss.elastic.co/u/wdffw)\
**Post date:** [April 4, 2022, 11:41am UTC](https://discuss.elastic.co/t/mapping-data-with-2-index/300495/3 "2022-04-04T11:41:10Z")

</div>

Hello,

By the way, it's not really that. I'll try to be more precise.  
In fact I want to be able to build a runtime mapping for using a calculation with two different indexes (index1 and index2) like this:

```auto
PUT /index1/_mapping
{
  "runtime": {
    "change": {
      "type": "keyword",
      "script": """
        List D = doc_for_index2['ip.keyword].value;
        def val = doc['myIp.keyword'].value;
        for (int i=0; i < D.length; i++){
          if ( val == D[i] ) return emit(val);}
      
        """
    }
  }
}

```

**NB : List D get all ip values of each document in index2 and then make the comparison with myIp in index1.**

---

<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:** [May 2, 2022, 11:41am UTC](https://discuss.elastic.co/t/mapping-data-with-2-index/300495/4 "2022-05-02T11:41:15Z")

</div>

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