String search
Learn how to search for personal data objects using a string
To search for objects in a collection using a full sting match, you use the CLI search objects or the REST API search objects operation, passing the property or properties you want to get and the collection name.
You can perform the full sting match on encrypted or plaintext properties.
Step-by-step
Say you have the buyers
collection you created in Create a collection. You want to retrieve name
and email
for all the buyers in this collection that meet a search requirement. For simplicity, assume that the buyers
collection contains only these 3 objects:
The buyers collection
+-----------------------------+------------+
| email | name |
+-----------------------------+------------+
| mr.john@somemail.com | John |
| john1234@anotheremail.com | John |
| mary@someemail.com | Mary |
+-----------------------------+------------+
Consider these 3 search requirements.
- A "match" requirement: The
name
must be "John". - An "in" (any of) requirement: The
email
must be either "mr.john@somemail.com" or "mary@someemail.com". - Both a "match" requirement and an "in" requirement: The
name
must be "John" and theemail
must be either "mr.john@somemail.com" or "mary@someemail.com".
The following sections demonstrate how to implement a query for each requirement using the CLI and REST API.
Specifying a "match" requirement
You can search for the objects with a "match" requirement using the CLI like this:
pvault object query \
--match name=John \
--props name,email \
--collection customers
The --match
option limits the results to those buyers whose name
is "John".
If required, you can specify additional --match
flags for other properties to limit the results further.
Alternatively, you can specify the search query in JSON format, using the --query-json
flag, like this:
pvault object query \
--query-json '{
"match": {
"name":"John"
}
}' \
--props name,email \
--collection customers
If required, you can specify values for other properties in the "match"
object to limit the results further.
For both options, you get a response similar to this:
Displaying 2 results.
+-----------------------------+------------+
| email | name |
+-----------------------------+------------+
| mr.john@somemail.com | John |
| john1234@anotheremail.com | John |
+-----------------------------+------------+
The response is paginated. See CLI pagination for more information about working with paginated responses.
You can also use the REST API like this:
curl -s -X POST \
--url 'http://localhost:8123/api/pvlt/1.0/data/collections/customers/query/objects?props=name,email&reason=AppFunctionality' \
--header 'Authorization: Bearer pvaultauth' \
--header 'Content-Type: application/json' \
--data '{
"match": {"name":"John"}
}'
If required, you can specify values for other properties in the "match"
object to limit the results further.
In this case, you get a response similar to this:
{
"results": [
{
"email": "mr.john@somemail.com",
"name": "John"
},
{
"email": "john1234@anotheremail.com",
"name": "John"
}
],
"paging": {
"size": 2,
"remaining_count": 0,
"cursor": ""
}
}
The response is paginated. See CLI pagination for more information about working with paginated responses.
Specifying an "in" requirement
You can search for the objects with an "in" requirement using the CLI like this:
pvault object query \
--in email=mr.john@somemail.com,mary@someemail.com \
--props name,email \
--collection customers
The --in
option limits the results to those buyers whose email
is either "mr.john@somemail.com" or "mary@someemail.com".
If required, you can specify additional --in
flags for other properties to limit the results further.
Alternatively, you can specify the search query in JSON format, using the --query-json
flag, like this:
pvault object query \
--query-json '{
"in": {
"email":[
"mr.john@somemail.com",
"mary@someemail.com"
]
}
}' \
--props name,email \
--collection customers
If required, you can specify values for other properties in the "in"
object to limit the results further.
For both options, you get a response similar to this:
Displaying 2 results.
+-----------------------------+------------+
| email | name |
+-----------------------------+------------+
| mr.john@somemail.com | John |
| mary@someemail.com | Mary |
+-----------------------------+------------+
The response is paginated. See CLI pagination for more information about working with paginated responses.
You can also use the REST API like this:
curl -s -X POST \
--url 'http://localhost:8123/api/pvlt/1.0/data/collections/customers/query/objects?props=name,email&reason=AppFunctionality' \
--header 'Authorization: Bearer pvaultauth' \
--header 'Content-Type: application/json' \
--data '{
"in": {
"email":[
"mr.john@somemail.com",
"mary@someemail.com"
]
}
}'
If required, you can specify values for other properties in the "in"
object to limit the results further.
In this case, you get a response similar to this:
{
"results": [
{
"email": "mr.john@somemail.com",
"name": "John"
},
{
"email": "mary@someemail.com",
"name": "Mary"
}
],
"paging": {
"size": 2,
"remaining_count": 0,
"cursor": ""
}
}
The response is paginated. See CLI pagination for more information about working with paginated responses.
Specifying a "match" and an "in" requirement
You can search for the objects with both a "match" and an "in" requirement using the CLI like this:
pvault object query \
--match name=John \
--in email=mr.john@somemail.com,john1234@anotheremail.com \
--props name,email \
--collection customers
If required, you can specify additional --in
and --match
flags for other properties to limit the results further.
Alternatively, you can specify the search query in JSON format, using the --query-json
flag, like this:
pvault object query \
--props name,email \
--collection customers \
--query-json '{
"match": {
"name":"John"
},
"in": {
"email":[
"mr.john@somemail.com",
"mary@some.com"
]
}
}'
If required, you can specify values for other properties in the "in"
and "match"
objects to limit the results further.
For both commands, you get a response similar to this:
Displaying 2 results.
+-----------------------------+------------+
| email | name |
+-----------------------------+------------+
| mr.john@somemail.com | John |
| john1234@anotheremail.com | John |
+-----------------------------+------------+
The response is paginated. See CLI pagination for more information about working with paginated responses.
You can also use the REST API like this:
curl -s -X POST \
--url 'http://localhost:8123/api/pvlt/1.0/data/collections/customers/query/objects?props=name,email&reason=AppFunctionality' \
--header 'Authorization: Bearer pvaultauth' \
--header 'Content-Type: application/json' \
--data '{
"match": {
"name":"John"
},
"in": {
"email":[
"mr.john@somemail.com",
"john1234@anotheremail.com"
]
}
}'
If required, you can specify values for other properties in the "in"
and "match"
objects to limit the results further.
In this case, you get a response similar to this:
{
"results": [
{
"email": "john1234@anotheremail.com",
"name": "John"
}
],
"paging": {
"size": 1,
"remaining_count": 0,
"cursor": ""
}
}
The response is paginated. See CLI pagination for more information about working with paginated responses.