Unspecified search

Sometimes, you might need to search across multiple fields for a certain value. In such a case, use unspecified search.

Out of the box, Order Service uses _search, which is a global field to search across multiple fields. While creating an index, you can use the copy_to parameter to associate fields to the global field for search in their field mappings. You can use the _search field to query against all the fields that are added to the global field, instead of having multiple queries for each of those individual fields.

Adding fields to _search while creating index

Use the copy_to parameter to associate fields to the global _search field in their mappings. The copy_to parameter copies individual field values to _search, which you can later use to run a query. You cannot use this parameter on object or nested types. The copy_to parameter is applicable only to individual fields, including the fields in an object and nested types. To associate fields to the _search field by using the copy_to parameter, refer to the following mapping specification.

{
 "index":
 {
  "id":"order",
  "mappings":
  {
   "BillToID":
   {
    "type":"keyword",
    "index":false,
    "store":false,
    "doc_values": false,
    "copy_to":"_search"
   },
   "BuyerUserId":
   {
    "type":"keyword",
    "index":true,
    "store":true,
    "copy_to":"_search"
   }
  }
 }
}

Running an unspecified search

Use the searchOrder API to run an unspecified search query. Refer to the following example of a query that searches for the value buyerUser1 using the _search field. The query returns orders that match the term buyerUser1 either in BillToID or BuyerUserId.

{
 "query":
 {
  "match":
  [
   {
     "condition":"MUST",
     "field":"_search",
     "value":"buyerUser1"
   }
  ]
 }
}