Friday, 23 April 2021

Can I subclass elasticsearch-dsl's IpRange to be used by django-elasticsearch-dsl?

How can one use the ip_range field type for CIDR notated IP addresses with django-elasticsearch-dsl?

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

I tried making a subclass 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()
    ...

Results in:

"mappings": {
  "_doc": {
    "properties": {
      "ipaddress": {
        "type": "text"
...


from Can I subclass elasticsearch-dsl's IpRange to be used by django-elasticsearch-dsl?

No comments:

Post a Comment