This section describes the configuration of a PSearch cluster and the REST API required to retrieve images and associated meta data.
Home > Edge > Manufacturing Edge > Guides > Dell Validated Design for Manufacturing Edge - Design Guide with Litmus > Pravega search Python-based image retrieval
This section describes the configuration of a PSearch cluster and the REST API required to retrieve images and associated meta data.
Pravega search requires configuration of a Pravega search cluster for every project. These can be configured as small, medium, and large, with predefined resources allocated for each configuration type.
Once a PSearch cluster is created, the REST API head API and UI URI are available for the specified project, as shown in the following code. It follows the format: psearch-{api/ui}-<project/scope name>-<SDP base domain name>.
# kubectl get ing -A | grep -I psearch
<Project/Scope Name> psearch-resthead-headless nginx-nautilus psearch-api-<project/scope name>.sdp.<SDP base domain name> <IP Address> Ports
<Project/Scope Name> psearch-ui nginx-nautilus psearch-ui-<project/scope name>.sdp.<SDP base domain name> <IP Address> Ports
Example output would be: cognex-1 psearch-ui nginx-nautilus psearch-ui-cognex-1.sdp.sdpdomain.lab 10.10.10.20 80,443 84d
Once the Pravega search cluster is created for a project, searchable streams can be created. Create a new stream, and optionally specify the Index Name and Mapping details necessary for the stream.
The following are some of the parameters required to run Python scripts for Pravega search:
[DEFAULT]
PRAVEGA_SCOPE = <Project/Scope Name>
PRAVEGA_STREAM = <Pravega Stream>
# Environment variables to be set in the script for stream manager
[PRAVEGA]
pravega_client_auth_method = Bearer
# SDP specific URI and authentication
pravega_client_tls_cert_path = <SDP Certificate>
pravega_client_auth_keycloak = <Keycloak secret JSON file>
pravega_controller_uri = <Pravega Controller URI>:443
[PSEARCH]
PSEARCH_USERNAME = admin_dashboard
PSEARCH_PASSWORD = admin_dashboard
PSEARCH_RESTHEAD = <Pravega Search REST Head for the Project/Scope>
PSEARCH_STREAM = <Pravega Searchable Stream>
PSEARCH_QUERY = <Query JSON>
URL = 'https://' + pravega_controller_uri +'/' + PSEARCH_STREAM + '-index/_search?'
basic_auth = HTTPBasicAuth(PSEARCH_USERNAME, PSEARCH_PASSWORD)
headers = {"Host": PSEARCH_RESTHEAD, "Content-type": "application/json" }
body = PSEARCH_QUERY
r = requests.post(URL, auth=basic_auth, verify=pravega_client_tls_cert_path, headers=headers, data=body)
The following code example shows some sample JSON-formatted queries.
# Searching for images with specific reject reasons
{ "query": {"match": {"rejectReason": {"query" : "Angle_Too_Small"} } } }'
# Searching for specific camera ID
{ "query": {"match": { "cameraId": { "query" : "Camera_1"} } } }’
# Searching for images within specific time range
{ "query": { "bool": {"filter": [{ "range": { "timestamp": { "lt": "2022/11/17_23:00:00","gt": "2022/11/15_00:00:00","format" : "yyyy/MM/dd_HH:mm:ss"} } } ] } }, "from": 0, "size": 25}'
# Searching for a specific criteria range
{"query": { "range": { "angle": { "gte": "80.00", "lte": "90.00"} } } }’
This section shows an example of accessing OpenSearch UI, which offers a graphical query interface for Psearch. Authentication to access the URL uses the SDP UI user name and credentials shown earlier, and then the OpenSearch login user name and password brings up the OpenSearch Dashboards. OpenSearch allows creation of dashboard and visualization capabilities. REST API-based queries are run using Management > Dev Tools.
The following figure shows a query in the Console of the OpenSearch dashboard.