diff --git a/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/config.py b/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/config.py index 54267926..66ba592e 100644 --- a/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/config.py +++ b/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/config.py @@ -24,30 +24,4 @@ def create_client(self): """Create es client.""" # try: client = Elasticsearch([{"host": str(DOMAIN), "port": str(PORT)}]) - - mapping = { - "mappings": { - "properties": { - "geometry": {"type": "geo_shape"}, - "id": {"type": "text", "fields": {"keyword": {"type": "keyword"}}}, - "properties__datetime": { - "type": "text", - "fields": {"keyword": {"type": "keyword"}}, - }, - } - } - } - - _ = client.indices.create( - index="stac_items", - mappings=mapping, - ignore=400, # ignore 400 already exists code - ) - - _ = client.indices.create( - index="stac_collections", - mappings={}, - ignore=400, # ignore 400 already exists code - ) - return client diff --git a/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/transactions.py b/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/transactions.py index 3c50095c..33770614 100644 --- a/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/transactions.py +++ b/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/transactions.py @@ -51,6 +51,25 @@ def create_item(self, model: stac_types.Item, **kwargs): if "created" not in model["properties"]: model["properties"]["created"] = str(now) + mapping = { + "mappings": { + "properties": { + "geometry": {"type": "geo_shape"}, + "id": {"type": "text", "fields": {"keyword": {"type": "keyword"}}}, + "properties__datetime": { + "type": "text", + "fields": {"keyword": {"type": "keyword"}}, + }, + } + } + } + + _ = self.client.indices.create( + index="stac_items", + body=mapping, + ignore=400, # ignore 400 already exists code + ) + self.client.index( index="stac_items", doc_type="_doc", id=model["id"], document=model )