Skip to content

Commit deb056e

Browse files
authored
Merge pull request #2 from jonhealy1/change_mappings
change mappings
2 parents a050390 + 80e224b commit deb056e

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/config.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,4 @@ def create_client(self):
2424
"""Create es client."""
2525
# try:
2626
client = Elasticsearch([{"host": str(DOMAIN), "port": str(PORT)}])
27-
28-
mapping = {
29-
"mappings": {
30-
"properties": {
31-
"geometry": {"type": "geo_shape"},
32-
"id": {"type": "text", "fields": {"keyword": {"type": "keyword"}}},
33-
"properties__datetime": {
34-
"type": "text",
35-
"fields": {"keyword": {"type": "keyword"}},
36-
},
37-
}
38-
}
39-
}
40-
41-
_ = client.indices.create(
42-
index="stac_items",
43-
mappings=mapping,
44-
ignore=400, # ignore 400 already exists code
45-
)
46-
47-
_ = client.indices.create(
48-
index="stac_collections",
49-
mappings={},
50-
ignore=400, # ignore 400 already exists code
51-
)
52-
5327
return client

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/transactions.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,25 @@ def create_item(self, model: stac_types.Item, **kwargs):
5151
if "created" not in model["properties"]:
5252
model["properties"]["created"] = str(now)
5353

54+
mapping = {
55+
"mappings": {
56+
"properties": {
57+
"geometry": {"type": "geo_shape"},
58+
"id": {"type": "text", "fields": {"keyword": {"type": "keyword"}}},
59+
"properties__datetime": {
60+
"type": "text",
61+
"fields": {"keyword": {"type": "keyword"}},
62+
},
63+
}
64+
}
65+
}
66+
67+
_ = self.client.indices.create(
68+
index="stac_items",
69+
body=mapping,
70+
ignore=400, # ignore 400 already exists code
71+
)
72+
5473
self.client.index(
5574
index="stac_items", doc_type="_doc", id=model["id"], document=model
5675
)

0 commit comments

Comments
 (0)