UpStart Commerce Search
Index
11min
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 create index 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 { "data" { "settings" { "index" { "number of shards" 2, "number of replicas" 1 } }, "mappings" { "properties" { "age" { "type" "integer" } } }, "aliases" { "sample alias1" {} } } } 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 placing document in index 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 { "data" \[ { "index" { " index" "hp characters" } }, { "name" "draco malfoy", "species" "human", "gender" "male", "house" "slytherin", "dateofbirth" "05 06 1980", "yearofbirth" 1980, "ancestry" "pure blood", "eyecolour" "grey", "haircolour" "blonde", "wand" { "wood" "hawthorn", "core" "unicorn tail hair", "length" 10 }, "patronus" "", "hogwartsstudent" true, "hogwartsstaff" false, "actor" "tom felton", "alive" true, "image" "http //hp api herokuapp com/images/draco jpg" }, { "index" { " index" "hp characters" } }, { "name" "minerva mcgonagall", "species" "human", "gender" "female", "house" "gryffindor", "dateofbirth" "04 10 1925", "yearofbirth" 1925, "ancestry" "half blood", "eyecolour" "", "haircolour" "black", "wand" { "wood" "", "core" "", "length" "" }, "patronus" "tabby cat", "hogwartsstudent" false, "hogwartsstaff" true, "actor" "dame maggie smith", "alive" true, "image" "http //hp api herokuapp com/images/mcgonagall jpg" } { "index" { " index" "hp characters" } }, { "name" "harry potter", "species" "human", "gender" "male", "house" "gryffindor", "dateofbirth" "31 07 1980", "yearofbirth" 1980, "ancestry" "half blood", "eyecolour" "green", "haircolour" "black", "wand" { "wood" "holly", "core" "phoenix feather", "length" 11 }, "patronus" "stag", "hogwartsstudent" true, "hogwartsstaff" false, "actor" "daniel radcliffe", "alive" true, "image" "http //hp api herokuapp com/images/harry jpg" } ] } 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 search index directly 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 { "search" { "query" { "query string" { "query" "draco" } } }, "tracking" "all" } note the search code used in the example above is the same as the one provided by opensearch response the following code block represents a snippet from the generated response { "result" { "queryid" "9faf0fb1 71c6 4515 b9a9 34a05e6b1085", "hits" { "total" { "value" 1, "relation" "eq" }, "hits" \[ { " index" "sp sitename default hp characters 000001", " source" { "name" "draco malfoy", "species" "human", "gender" "male", "house" "slytherin", "dateofbirth" "05 06 1980", "yearofbirth" 1980, "ancestry" "pure blood", "eyecolour" "grey", "haircolour" "blonde", "wand" { "wood" "hawthorn", "core" "unicorn tail hair", "length" 10 }, "patronus" "", "hogwartsstudent" true, "hogwartsstaff" false, "actor" "tom felton", "alive" true, "image" "http //hp api herokuapp com/images/draco jpg" } } ] } } } 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' search with query pipeline before diving into searching with query pipelines, it is important to understand the concept of query pipeline docid\ syjm cutkdxgvmtsey2x 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 { "search" { "query" { "query string" { "query" "half blood" } } }, "tracking" "all", "querypipelineid" "hprules" } 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 response the following code block represents a snippet from the generated response { "result" { "queryid" "73715673 fc69 45c8 99b8 cbd0a22fd445", "data" { "hits" { "total" { "value" 1, "relation" "eq" }, "hits" \[ { " index" "sp sitename default hp characters 000001", " type" " doc", " id" "jcoi1h4br gifr7ddfmo", " source" { "name" "harry potter", "species" "human", "gender" "male", "house" "gryffindor", "dateofbirth" "31 07 1980", "yearofbirth" 1980, "ancestry" "half blood", "eyecolour" "green", "haircolour" "black", "wand" { "wood" "holly", "core" "phoenix feather", "length" 11 }, "patronus" "stag", "hogwartsstudent" true, "hogwartsstaff" false, "actor" "daniel radcliffe", "alive" true, "image" "http //hp api herokuapp com/images/harry jpg" } } ] } }, "aggregations" {}, "type" "searchresponseanswer" } } notice that the "half blood" document in the ancestry is returned in the search results