django-elasticsearch-dsl icon indicating copy to clipboard operation
django-elasticsearch-dsl copied to clipboard

How can I use ip_range field type?

Open landonstewart opened this issue 3 years ago • 0 comments

How can one use the ip_range field type for CIDR notated IP addresses?

https://www.elastic.co/guide/en/elasticsearch/reference/current/range.html#ip-range

I tried making a subclass like this but it results in a field mapping of "type": "text"

...
from django_elasticsearch_dsl.fields import DEDField
from elasticsearch_dsl.field import IpRange
...

class IpRangeField(DEDField, IpRange):
    """Subclass based on DedField and IpRange."""


@registry.register_document
class FeedDataDocument(Document):
    """FeedData elasticsearch."""
    ...
    ipaddress = IpRangeField()
    ...
"mappings": {
  "_doc": {
    "properties": {
      "ipaddress": {
        "type": "text"
...

landonstewart avatar Apr 12 '21 21:04 landonstewart