Skip to content

Commit

Permalink
Update args to include query_string | simple_query_string as options
Browse files Browse the repository at this point in the history
  • Loading branch information
m453h committed Nov 15, 2024
1 parent 311ae4c commit 26f4afc
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions indexer/scripts/elastic-update-canonical-domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, process_name: str, descr: str) -> None:
self.updates_buffer: List[Dict[str, Any]] = []
self.buffer_size: int = 0
self.index_name: str = ""
self.query_format: Literal["DLS", "query_string"] = "query_string"
self.query_type: Optional[Literal["query_string", "simple_query_string"]] = None
self.total_matched_docs: Optional[int] = None

def define_options(self, ap: argparse.ArgumentParser) -> None:
Expand Down Expand Up @@ -57,11 +57,10 @@ def define_options(self, ap: argparse.ArgumentParser) -> None:
)

ap.add_argument(
"--format",
dest="query_format",
default="query_string",
choices=["DSL", "query_string"],
help="The elasticsearch query format (supported values are: [DSL, query_string])",
"--type",
dest="query_type",
choices=["query_string", "simple_query_string"],
help="The elasticsearch query format (supported values are: [query_string, simple_query_string])",
)

ap.add_argument(
Expand All @@ -82,7 +81,7 @@ def process_args(self) -> None:
self.batch_size = args.batch_size
self.buffer_size = int(args.buffer_size)
self.keep_alive = args.keep_alive
self.query_format = args.query_format
self.query_type = args.query_type
self.query = self.validate_query(args.query)

@property
Expand All @@ -100,8 +99,10 @@ def validate_query(self, query: str) -> Optional[Dict[str, Any]]:
"""
validated_query = None
try:
if self.query_format == "query_string":
if self.query_type == "query_string":
query_dict = {"query": {"query_string": {"query": query}}}
elif self.query_type == "simple_query_string":
query_dict = {"query": {"simple_query_string": {"query": query}}}
else:
query_dict = json.loads(query)
validation_result = self.es_client.indices.validate_query(
Expand Down

0 comments on commit 26f4afc

Please sign in to comment.