Jump to: navigation, search

Sort Order in Interaction Search

Results of interaction searches, including searches returning 100+ records, can now be sorted. This new functionality is available through an evolution of InteractionListGet and ContactListGet functions. These now accept Elasticsearch queries associated with the key ESQuery.

ESQuery can be provided as a new parameter or as an attribute name in search criteria.

ESQuery as New Parameter

 
TenantId 	102 
Segment 	Airbnb 
ESQuery 	"query" : {
 		"bool" : {
			"must" : { 
				"term" : { "ThreadId" : "WX345SBGA34TFGGS" } 
			}, 
			"must_not" : { 
				"range" : {
					 "Status" : { "from" : 1, "to" : 3 }
				}
			}
		 }
	}
AttributeList 	
	AttrName 	Id 
	AttrName 	TypeId 
	AttrName 	SubtypeId

ESQuery as Attribute Name in Search Criteria

TenantId 	102 
Segment 	Airbnb 
SearchCriteria 	EQUAL 	
		AttrName 	ESQuery 
		AttrValue 	+ThreadId:WX345SBGA34TFGGS +Status:2 
AttributeList 	
	AttrName 	Id 	
	AttrName 	TypeId 	
	AttrName 	SubtypeId

Compatibility

The queries must be compatible with Elasticsearch 5.5 (documentation is at https://www.elastic.co/guide/en/elasticsearch/reference/5.5/query-dsl.html).

Important
The previous full-text search API function from UCS 8.5x is deprecated.

Some specific cases

In Elasticsearch queries, most of the time the database object field names (ContactId, TConnectionId...) must be used as they are. However the following examples show the most important exceptions.

Important
The interaction parameters Text, StructuredText, Comment and AllAttributes are not sortable. Attempts to sort by those fields will generate an error.

Sorting interactions by subject

To sort interactions by subject the suffix raw must be added.

Example

Service=OMInteractions
Method=InteractionListGet
Parameters={
 TenantId=1
 ESQuery={
	"query":{
		"query_string":{
			"query":"Subject:*qwertyuiop*"
		}
	},
	"sort":[
		{
			"Subject.raw":{"order":"desc"}
		}
	]
 }
 AttributeList={"AttrName":AttrName=Subject}
}

Search by custom parameter

You can search and sort interactions by any custom parameter configured as an Interaction Attribute in the Configuration Server.

Example with custom parameter ReasonCode

Service=OMInteractions
Method=InteractionListGet
Parameters={ 
 TenantId=1
 ESQuery={
	"query":{
		"query_string":{
			"query":"Attributes.ReasonCode:T*"
		}
	},
	"sort":[
		{
			"Attributes.ReasonCode":{"order":"asc"}
		}
	]
 }
 AttributeList={
	AttrName=TConnectionId
	AttrName=PhoneNumber
	AttrName=ReasonCode
 }
}

Search by standard attributes

To search for contacts by standard attributes (EmailAddress, PhoneNumber, FirstName, LastName), the prefix AttributeValues must be added to the contact attributes.

To sort contacts by standard attributes (EmailAddress, PhoneNumber, FirstName, LastName), the prefix AttributeValues and suffix raw must be added

Example of searching and sorting contacts by email address

Service=OMContacts
Method=ContactListGet
Parameters={ 
 ESQuery={
	"query":{
		"match":{
			"AttributeValues.EmailAddress":{
				"query":"anyone@anywhere.net",
				"operator":"and",
				"zero_terms_query":"all"
			}
		}
	},
	"sort":[
		{
			"AttributeValues.EmailAddress.raw":{"order":"desc"}
		}
	]
 }
 AttributeList={
	AttrName=FirstName
	AttrName=LastName
	AttrName=EmailAddress
 }
 TenantId=1
}

Search for contacts by primary addresses only

To search for contacts by primary addresses only, the prefix PrimaryAttributes must be added to the attribute EmailAddress.

Example of searching and sorting contacts by the primary email address

Service=OMContacts
Method=ContactListGet
Parameters={
 ESQuery={
	"query":{
		"query_string":{
			"query":"+PrimaryAttributes.EmailAddress:*Bedethaelb +PrimaryAttributes.EmailAddress:*gen"
		}
	},
	"sort":[
		{
			"AttributeValues.EmailAddress.raw":{"order":"asc"}
		}
	]
 }
 AttributeList={
	"AttrName":AttrName=EmailAddress
 }
 TenantId=1
}

Search by custom contact attributes

Custom contact attributes can be used in queries, as follows:

  • Custom contact attributes of type string must have the prefix AttributeValues.
  • Custom contact attributes of type date must have the prefix AttributeValuesDate.

Example using custom contact attributes CustomerSegment (string) and DayOfOrder (date) created in Tenant 1

Service=OMContacts
Method=ContactListGet
Parameters={ 
 TenantId=1
 AttributeList={
	AttrName=DayOfOrder
	AttrName=EmailAddress
 }
 ESQuery={
	"query":{
		"query_string":{
			"query":"+AttributeValues.CustomerSegment:aeb02b26882b4eac +AttributeValuesDate.DayOfOrder:{1966-02-13T01:15:30.005Z TO 1968-02-13T01:16:00.000Z}",
		},
		"sort":[
			{
				"AttributeValues.EmailAddress.raw":{"order":"asc"}
			}
		]
	}
 }
}

Feedback

Comment on this article:

blog comments powered by Disqus
This page was last modified on May 28, 2018, at 21:25.