Index
An index is a structure that stores data and is searchable. All the data that is to be searched is present in multiple indexes. Data is populated by placing multiple "documents" in the index. There can be multiple indexes and each is managed independently. Indexes are a crucial part of the search operation. In a single route, there can be one or many indexes that hold the data. Each query that is searched in a route is looked for in all the indexes that are present in the route.
The indexing operations utilized by NoChannel Search are provided by OpenSearch. To understand every individual function and property of each variable in the above-mentioned code block, refer to the OpenSearch Documentation here.
To understand the concept of indexes and documents better, we will create an index and perform for Harry Potter characters.
The API call to create the index is:
POST https://api.upstartcommerce.com/v1/search/index/hp_characters
Notice that the name of the index that is to be created is mentioned at the end of the URL i.e. hp_characters.
The following code block is a representation of how to create an index.
Notice that there are three different things being defined in the data code block i.e. settings, mappings, and aliases. If there are no values defined in the data block, the index will automatically set to its default values.
You can place a single or multiple document on an index. Continuing the example above, the API call to place the documents in bulk is:
POST https://api.upstartcommerce.com/v1/search/index/bulk
Notice that the name of the index is the same as the one created above is hp_characters and "doc" specifies that it is a document.
Notice, that multiple documents are being added to the index. Before providing the document data, the name of the index is mentioned i.e. hp_characters.
As the name implies, this search type directly goes through the index without applying or utilizing query pipelines or rules. The API call for the search-direct index is:
POST https://api.upstartcommerce.com/v1/search/index/hp_characters/search-direct
Notice that the name of the index "hp_characters" is mentioned before specifying the type of search i.e. "search-direct".
In continuation of the example used in index and document creation, consider the following block:
Note: The search code used in the example above is the same as the one provided by OpenSearch.
The following code block represents a snippet from the generated response:
Notice that the value of hits is 1 in the response. This means that one response is retrieved by the search.
Since, the search term was "Draco", all the data details retrieved by Search is of 'Draco Malfoy'.
Before diving into searching with query pipelines, it is important to understand the concept of Query Pipeline.
Continuing the example discussed in the query pipeline documentation, we will assume that the query pipeline and query rule filter have been created. We will now search calls through it. The API call for the search with the query pipeline is:
POST https://api.upstartcommerce.com/v1/index/hp_characters/search
Notice that the name of the index "hp_characters" is explicitly mentioned. This means that the search will consider one associated query pipeline per call.
The following search code block has the query value "half blood" in it.
Notice that the value of the query pipeline ID is set to hprules which is the name of the pipeline we would like our search to go through.
The following code block represents a snippet from the generated response:
Notice that the "half blood" document in the ancestry is returned in the search results.