LoanPro provides a powerful search function through OpenSearch's /search
endpoint. Through this endpoint, you can query, sort and aggregate data to your needs.
Documents in search is any unit that stores information in a JSON format. In a database, a document can represent a single row row in a table or an object such as a card, cardholder, or swipe. When you perform a search, documents related to your search will be returned.
An index is how search organizes your documents. Where a document is an individual row or object, an index represents the database. When you perform a search, you query data contained in an index. Search will index new documents in real time. However, server load can lead to indexing being delayed. If a new document does not appear in your search, it might not be indexed.
LoanPro uses OpenSearch query objects to perform most searches. The format of the query object is below.
{
"search": {
"query":{
<query data>
}
}
}
The query object is the OpenSearch query context—the contents of this object will be formatted according to OpenSearch's documentation. Here, you can place multiple queries to retrieve a specific set or wide range of information.
The search
object has its own set of attributes.
Attribute: | Definition: |
---|---|
size | This attribute determines the number of results to return. This number cannot exceed 10,000. > To retrieve results past 10,000. Use from to shift the starting index to 10,001 and change size to 20,000. |
from | This attribute determines where the index for returned results will begin. |
track_total_hits | This attribute determines whether the search tracks the number of results that were returned. |
For examples of search queries, see our POST
search customers request.
Basic Queries
Due to the complexity of OpenSearch and the nature of Secure Payment's data, not all query types are officially supported by LoanPro. The official features have a guarantee of functionality—all others are not guaranteed to provide desires results or usability. Here is a list of supported basic query types:
Query Type | Description |
---|---|
match | This query searches a specific field for the specified value. |
multi_match | This query searches multiple fields for the specified value. |
query_string | This query parses the string based on query string syntax to create powerful and concise queries. |
simple_query_string | This query specifies multiple arguments delineated by regular expressions. |
Compound queries
Compound queries are used to combine multiple queries and use logical operations. This allows for performing queries such as find all cards where the processing type is credit and the card status is active.
Each compound query is composed of clauses or collections of either more compound or basic query types. All clauses are evaluated from the innermost layer to the outermost layer. Here is a list of supported compound queries:
Query Type: | Description: |
---|---|
bool | This returns whether a match was made based on one or more boolean clauses. The clauses are: -must: The clause must be matched. -filter: Restricts results to match the clause. -should: The clause should be matched. If it is the only clause type, all nested queries are optional. -must_not: The clause must not match. |
Query syntax
OpenSearch's query_string
uses Apache Lucene query syntax.
The simple_query_string
uses regular expression operators. It supports the following operators.
Operator: | Description: |
---|---|
+ | Acts as the AND operator. |
| | Acts as the OR operator. |
* | Acts as a wildcard operator. |
" | Wraps several terms into a phrase. |
( ,) | Wraps a clause for operation priority. |
~n | When used after a term, sets fuzziness . When used after a phrase, sets slop . |
- | Negates the term. |
Query context
You can search using queries. A query clause using a query allows you to search for a non-binary response. Meaning, the contents of a document are similar or relevant to your search. This is useful when searching for a keyword or phrase. Below is an example of a queried search.
{
"search": {
"size": 10000,
"from": 0,
"track_total_hits": true,
"query": {
"bool": {
"must": {
"query_string": {
"query": "*john*",
"fields": [
"first_name",
"middle_name",
"last_name",
"email"
]
}
}
}
}
}
}
This example search uses a query_string
object. Within it, the query
searches for *john*
in the fields for first_name
, middle_name
, last_name
, and email
.
Filter context
You can search using filters. A query clause using a filter allows you to search for a binary response. Meaning, the contents of a document will match your search exactly. You can use a filter context to search for customer by birth year, or swipes created across a set of dates. Below is an example of a filtered search.
{
"search":{
"size": 10000,
"from": 0,
"track_total_hits": true,
"query": {
"bool": {
"filter": [
{
"term": {
"processing_type": "credit"
}
},
{
"term":{
"card_status": "expired"
}
}
]
}
}
}
}
This example search uses a filter
. Within it, the filter searches along a two term
objects, and searches for processing_type
credit and card_status
expired.