Skip to content

Instantly share code, notes, and snippets.

@shentonfreude
Created April 19, 2016 17:54
Show Gist options
  • Save shentonfreude/209d0c51901297f61387099c310672c0 to your computer and use it in GitHub Desktop.
Save shentonfreude/209d0c51901297f61387099c310672c0 to your computer and use it in GitHub Desktop.
Get the endpoints by the human name, then search on a single field with structured query
aws_region = config['AWS']['region']
search_domain_name = config['AWS']['cloudsearch_domain_name'] # e.g., avail-search-dev
cs = boto3.client("cloudsearch")
cs_domain = cs.describe_domains(DomainNames=[search_domain_name])['DomainStatusList'][0]
cs_doc_ep = cs_domain['DocService']['Endpoint']
cs_doc = boto3.client('cloudsearchdomain',
endpoint_url='https://' + cs_doc_ep,
region_name=aws_region)
cs_search_ep = cs_domain['SearchService']['Endpoint']
cs_search = boto3.client('cloudsearchdomain',
endpoint_url='https://' + cs_search_ep,
region_name=aws_region)
# Search by field nasa_id:
res = cs_search.search(query="nasa_id: '201404030002HQ'", queryParser='structured')
# returns res['hits']['found'] == 0, res['hits']['hit'] == [] if none
@shentonfreude
Copy link
Author

We get the AWS hairy-named endpoints from our simple human name. Then we do a search on a single field using a 'structured' query, rather than 'simple' matching against all text fields. Not shown is how to add a document to the CloudSearch using the endpoint we discover.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment