You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by se...@apache.org on 2021/12/12 16:21:49 UTC
[incubator-ponymail-foal] branch master updated: Add option to create missing index
This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git
The following commit(s) were added to refs/heads/master by this push:
new f337282 Add option to create missing index
f337282 is described below
commit f33728277f6a4c89b226a44364f902792bb5679d
Author: Sebb <se...@apache.org>
AuthorDate: Sun Dec 12 16:21:40 2021 +0000
Add option to create missing index
---
tools/mappings.py | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/tools/mappings.py b/tools/mappings.py
index a3e2740..bcfb572 100755
--- a/tools/mappings.py
+++ b/tools/mappings.py
@@ -45,6 +45,18 @@ parser.add_argument(
action="store_true",
help="Create the missing mapping(s)",
)
+parser.add_argument(
+ "--shards",
+ dest="shards",
+ type=int,
+ help="Create the missing indices",
+)
+parser.add_argument(
+ "--replicas",
+ dest="replicas",
+ type=int,
+ help="Create the missing indices",
+)
parser.add_argument('names', nargs='*')
args = parser.parse_args()
@@ -53,6 +65,22 @@ def check_mapping(index):
mappings_expected = mapping_file[index]['properties']
index_name = elastic.index_name(index)
+
+ # Check that index exists
+ if not elastic.indices.exists(index_name):
+ if args.shards and args.replicas is not None:
+ print("Creating index")
+ settings = {"number_of_shards": args.shards, "number_of_replicas": args.replicas}
+ elastic.indices.create(
+ index=index_name, body={"mappings": mapping_file[index], "settings": settings}
+ )
+ print("Created index!")
+ return
+ else:
+ print("Index not found!")
+ print("Specify --shards and --replicas to create the index")
+ return
+
# actual mappings
mappings = elastic.indices.get_mapping(index=index_name)[index_name]['mappings']['properties']