How to perform an IP range query / filter

I am trying to get an IP range request to work on a set of documents and I am not getting any results.

Mapping (I tried both analyzed, and not_analyzed):

   "mappings": {
      "addy": {
         "properties": {
            "add": {
               "type": "ip",
               "not_analyzed":"true"
            }
         }
      }
   }

The data looks like this (many examples of this with different meanings)

   "_source": {
       "add": "192.168.1.15"
   }

Now I looked at the ES official docs, but there was no example of an IP range, but I found it on Git that didn't work. It looks like this:

    "query": {
        "query_string": {
           "default_field": "add",
           "query": "add:[192.168.1.5 TO 192.168.1.15]"
        }
    }

The above encouraged parsing errors when I was fat, sorting through my fields and addresses, but in the end did not give any results.

I also tried the standard range syntax:

"filter": {
    "range": {
       "add": {
          "from": "192.168.1.5",
          "to": "192.168.1.25"
       }
    }
}

Which also did not give any results. How to request a range of IP addresses?

+4
source share
1

ip not_analyzed, . , :

curl -XPUT localhost:9200/addies -d '{
   "mappings": {
      "addy": {
          "properties":{
             "add": { "type": "ip"}
          }
      }
   }
}'

, :

curl -XPUT localhost:9200/addies/addy/1 -d '{"add": "192.168.1.100"}'
curl -XPUT localhost:9200/addies/addy/2 -d '{"add": "192.168.1.101"}'
curl -XPUT localhost:9200/addies/addy/3 -d '{"add": "192.168.1.102"}'
curl -XPUT localhost:9200/addies/addy/4 -d '{"add": "192.168.1.110"}'

, , query_string, :

curl -XPOST localhost:9200/addies/addy/_search -d '{
  "query": {
    "query_string": {
      "query": "add:[192.168.1.100 TO 192.168.1.102]"
    }
  }
}'

UPDATE:

, range :

curl -XPOST localhost:9200/addies/addy/_search -d '{
  "query": {
    "range": {
      "add": {
        "gte": "192.168.1.100",
        "lte": "192.168.1.102"
      }
    }
  }
}'
+6

Source: https://habr.com/ru/post/1598726/


All Articles