Mapping_data with 2 index

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

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"]
}
}

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

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

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:

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.

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