Changeset View
Changeset View
Standalone View
Standalone View
swh/search/elasticsearch.py
Show First 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | class ElasticSearch: | ||||
def initialize(self) -> None: | def initialize(self) -> None: | ||||
"""Declare Elasticsearch indices and mappings""" | """Declare Elasticsearch indices and mappings""" | ||||
if not self._backend.indices.exists(index=self.origin_index): | if not self._backend.indices.exists(index=self.origin_index): | ||||
self._backend.indices.create(index=self.origin_index) | self._backend.indices.create(index=self.origin_index) | ||||
self._backend.indices.put_mapping( | self._backend.indices.put_mapping( | ||||
index=self.origin_index, | index=self.origin_index, | ||||
body={ | body={ | ||||
"date_detection": False, | |||||
"properties": { | "properties": { | ||||
# sha1 of the URL; used as the document id | # sha1 of the URL; used as the document id | ||||
"sha1": {"type": "keyword", "doc_values": True,}, | "sha1": {"type": "keyword", "doc_values": True,}, | ||||
# Used both to search URLs, and as the result to return | # Used both to search URLs, and as the result to return | ||||
# as a response to queries | # as a response to queries | ||||
"url": { | "url": { | ||||
"type": "text", | "type": "text", | ||||
# To split URLs into token on any character | # To split URLs into token on any character | ||||
Show All 15 Lines | def initialize(self) -> None: | ||||
"properties": { | "properties": { | ||||
"@context": { | "@context": { | ||||
# don't bother indexing tokens in these URIs, as the | # don't bother indexing tokens in these URIs, as the | ||||
# are used as namespaces | # are used as namespaces | ||||
"type": "keyword", | "type": "keyword", | ||||
} | } | ||||
}, | }, | ||||
}, | }, | ||||
} | }, | ||||
}, | }, | ||||
) | ) | ||||
@timed | @timed | ||||
def flush(self) -> None: | def flush(self) -> None: | ||||
self._backend.indices.refresh(index=self.origin_index) | self._backend.indices.refresh(index=self.origin_index) | ||||
@timed | @timed | ||||
▲ Show 20 Lines • Show All 128 Lines • Show Last 20 Lines |