TomonoriSoejima/Tejun

How to test runtime field

Opened this issue · 0 comments

PUT /ip_addresses_index
{
  "mappings": {
    "properties": {
      "ip_addresses": {
        "type": "ip"
      }
    }
  }
}


PUT /ip_addresses_index/_doc/1
{
  "ip_addresses": [
    "0.0.0.0",
    "192.168.1.1",
    "192.168.1.2",
    "192.168.1.3",
    "192.168.1.4",
    "192.168.1.5"
  ]
}


GET ip_addresses_index/_search


GET /ip_addresses_index/_search
{
  "script_fields": {
    "filtered_ip_addresses": {
      "script": {
        "lang": "painless",
        "source": """
          ArrayList ips = new ArrayList();
          for (def ip : doc['ip_addresses']) {
            if (!ip.equals('0.0.0.0')) {
              ips.add(ip);
            }
          }
          return ips;
        """
      }
    }
  },
  "query": {
    "match_all": {}
  }
}