in MMS/dicom_featurization_service.py [0:0]
def postprocess(self, imageid, viewposition, vectorarray, esendpoint):
# index feature vector
if self.access_key is not None and self.secret_key is not None:
my_session = boto3.session.Session(
aws_access_key_id=self.access_key,
aws_secret_access_key=self.secret_key
)
else:
my_session = boto3.session.Session()
credentials = my_session.get_credentials()
awsauth = AWS4Auth(
credentials.access_key,
credentials.secret_key,
self.aws_region,
'es',
session_token=credentials.token
)
if self.es_index is not None:
es = Elasticsearch(
hosts = [{'host': esendpoint, 'port': 443}],
http_auth = awsauth,
use_ssl = True,
verify_certs = True,
connection_class = RequestsHttpConnection
)
# Creating the Elasticsearch index if not exists
if es.indices.exists(index=self.es_index):
logging.info('##### ES index {} already exists. #######'.format(self.es_index))
else:
knn_index = {
"settings": {
"index.knn": True
},
"mappings": {
"properties": {
"feature_vector": {
"type": "knn_vector",
"dimension": 1024
}
}
}
}
es.indices.create(
index=self.es_index,
body=knn_index,
ignore=400
)
response = es.index(
index=self.es_index,
id=imageid,
body={
"feature_vector": vectorarray,
"viewPosition": viewposition
}
)
return response
else:
return 'Failed to index KNN: No ES endpoint or index'