Jump to: navigation, search

Advanced Elasticsearch features

UCS 9.1 exposes the Elasticsearch API, which creates a number of advanced search possibilities:

Highlight

The Highlight feature allows a Google-like presentation of results.

The following sample shows an InteractionListGet request highlighting the term 'hero' wrapped with tags <mytag> and </mytag>. By default, the highlighting will wrap highlighted text in <em> and </em>.

Sample request and response

Request

Service=OMInteractions
Method=InteractionListGet
Type=Request
Parameters={
	ESQuery={
		"query":{
			"term":{
				"Text":"hero"
			}
		},
		"highlight":{
			"pre_tags":["<mytag>"],
			"post_tags":["</mytag>"],
			"fields":{"Text":{}}
		},
		"size":10000
	}
	TenantId=1
	AttributeList={
		AttrName=Text
		AttrName=ESQuery
	}
}

Response

Service=OMInteractions
Method=InteractionListGet
Type=Response
Parameters={
	PageSize=4
	InteractionData={
		0={
			Id='10024ODh478xcEox'
			Attributes={
				Text='In Greek mythology, Achilles or Achilleus was a Greek hero of the Trojan War and the central character and greatest warrior of Homer's Iliad. His mother was the immortal Nereid Thetis, and his father, the mortal Peleus, was the king of the Myrmidons.Achilles' most notable feat during the Trojan War was the slaying of the Trojan hero Hector outside the gates of Troy. Although the death of Achilles is not presented in the Iliad,other sources concur that he was killed near the end of the Trojan War by Paris, who shot him in the heel with an arrow. Later legends (beginning with a poem by Statius in the 1stcentury AD) state that Achilles was invulnerable in all of his body except for his heel because, when his mother Thetis dipped him in the river Styx as an infant, she held him by oneof his heels. Alluding to these legends, the term "Achilles heel" has come to mean a point of weakness, especially in someone or something with an otherwise strong constitution.'
				ESQuery={
					_shards={
						total=5
						failed=0
						successful=5
					}
					hits={
						total=4
						max_score=2
					}
					highlight={
						Text='In Greek mythology, Achilles or Achilleus was a Greek <mytag>hero</mytag> of the Trojan War and the central'
						Text=' was the slaying of the Trojan <mytag>hero</mytag> Hector outside the gates of Troy. Although the death of Achilles'
					}
					took=1
					_index='ks_ucs9_ci_interaction_index@'
					_type='Interaction'
					_source={Id='10024ODh478xcEox'}
					timed_out='false'
					_id='10024ODh478xcEox'
					_score=2
				}
				TenantId=1
			}
		}
		1={
			Id='10024ODh478zZTOg'
			Attributes={
				Text='In Greek mythology, Perseus is the legendary founder of Mycenae and of the Perseid dynasty, who, alongside Cadmus and Bellerophon, was the greatest Greek hero and slayer of monstersbefore the days of Heracles.[1] He beheaded the Gorgon Medusa for Polydectes and saved Andromeda from the sea monster Cetus. He was the son of Zeus and the mortal Dana, as well as the half-brother and great-grandfather of Heracles.'
				ESQuery={
					highlight={
						Text=', alongside Cadmus and Bellerophon, was the greatest Greek <mytag>hero</mytag> and slayer of monstersbefore the days of'
					}
					_index='ks_ucs9_ci_interaction_index@';_type='Interaction';_source={Id='10024ODh478zZTOg'}
					_id='10024ODh478zZTOg'_score=2
				}
				TenantId=1
			}
		}
		2={
			Id='10024ODh478u4Y4o'
			Attributes={
				Text='Heracles was a divine hero in Greek mythology, the son of Zeus and Alcmene, foster son of Amphitryon and great-grandson and half-brother (as they are both sired by the god Zeus) of Perseus. He was the greatest of the Greek heroes, a paragon of masculinity, the ancestor of royal clans who claimed to be Heracleidae, and a champion of the Olympian order  against chthonic monsters. In Rome and the modern West, he is known as Hercules, with whom the later Roman emperors, in particular Commodus and Maximian, often identified themselves. The Romans adopted the Greek version of his life and works essentially unchanged, but added anecdotal detail of their own, some of it linking the hero with the geography of the  Central Mediterranean. Details of his cult were adapted to Rome as well.'
				ESQuery={
					highlight={
						Text='Heracles was a divine <mytag>hero</mytag> in Greek mythology, the son of Zeus and Alcmene, foster son of'
						Text=' essentially unchanged, but added anecdotal detail of their own, some of it linking the <mytag>hero</mytag> with the'
					}
					_index='ks_ucs9_ci_interaction_index@'
					_type='Interaction'
					_source={Id='10024ODh478u4Y4o'}
					_id='10024ODh478u4Y4o'
					_score=2
				}
				TenantId=1
			}
		}
		3={
			Id='10024ODh478CNU3e'
			Attributes={
				Text='Jason was an ancient Greek mythological hero who was the leader of the Argonauts whose quest for the Golden Fleece featured in Greek literature. He was the son of Aeson,the rightful king of Iolcos. He was married to the sorceress Medea. He was also the great-grandson of the messenger god Hermes, through his mother's side.Jason appeared in various literary works in the classical world of Greece and Rome, including the epic poem Argonautica and the tragedy Medea. In the modern world,Jason has emerged as a character in various adaptations of his myths, such as the 1963 film Jason and the Argonauts and the 2000 TV miniseries of the same name.Jason has connections outside the classical world, being the mythical founder of the city of Ljubljana, the capital of Slovenia.'
				ESQuery={
					highlight={
						Text='Jason was an ancient Greek mythological <mytag>hero</mytag> who was the leader of the Argonauts whose quest for'
					}
					_index='ks_ucs9_ci_interaction_index@'
					_type='Interaction'
					_source={Id='10024ODh478CNU3e'}
					_id='10024ODh478CNU3e'
					_score=2
				}
				TenantId=1
			}
		}
	}
	HasNext='FALSE';
}

"More like this"

This feature allows you to search for items that are similar to one item. For example, you can provide the ID of an interaction and search for other interactions that look similar.

In the following sample InteractionListGet finds the two interactions containing the word mythology (length:9) in the Text field like the provided interaction (id:10024ODh48p7EqOY).

Sample request and response

Request

Service=OMInteractions
Method=InteractionListGet
Type=Request
Parameters={
	ESQuery={
		"query":{
			"more_like_this":{
				"min_doc_freq":1,
				"min_word_length":9,
				"max_query_terms":1,
				"like":[{
					"_id":"10024ODh48p7EqOY",
					"_index":"ks_ucs9_ci_interaction_index@"
				}],
				"min_term_freq":1,
				"fields":["Text"]
			}
		},
		"size":10000
	}
	TenantId=1
	AttributeList={
		AttrName=Subject
		AttrName=Text
		AttrName=ESQuery
	}
}

Response

Service=OMInteractions
Method=InteractionListGet
Type=Response
Parameters={
	PageSize=2
	InteractionData={
		0={
			Id='10024ODh48pazWIU'
			Attributes={
				Subject='Achilles';
				Text='In Greek mythology, Achilles or Achilleus was a Greek hero of the Trojan War and the central character and greatest warrior of Homer's Iliad. His mother was the immortal Nereid Thetis, and his father, the mortal Peleus, was the king of the Myrmidons.Achilles' most notable feat during the Trojan War was the slaying of the Trojan hero Hector outside the gates of Troy. Although the death of Achilles is not presented in the Iliad,other sources concur that he was killed near the end of the Trojan War by Paris, who shot him in the heel with an arrow. Later legends (beginning with a poem by Statius in the 1stcentury AD) state that Achilles was invulnerable in all of his body except for his heel because, when his mother Thetis dipped him in the river Styx as an infant, she held him by oneof his heels. Alluding to these legends, the term "Achilles heel" has come to mean a point of weakness, especially in someone or something with an otherwise strong constitution.'
				ESQuery={
					_shards={
						total=5
						failed=0
						successful=5
					}
					hits={
						total=2
						max_score=2
					}
					took=1
					_index='ks_ucs9_ci_interaction_index@'
					_type='Interaction'
					_source={Id='10024ODh48pazWIU'}
					timed_out='false'
					_id='10024ODh48pazWIU'
					_score=2
				}
				TenantId=1
			}
		}
		1={
			Id='10024ODh48pdnzyg'
			Attributes={
				Subject='Perseus'
				Text='In Greek mythology, Perseus is the legendary founder of Mycenae and of the Perseid dynasty, who, alongside Cadmus and Bellerophon, was the greatest Greek hero and slayer of monstersbefore the days of Heracles. He beheaded the Gorgon Medusa for Polydectes and saved Andromeda from the sea monster Cetus. He was the son of Zeus and the mortal Dana, as well as the half-brother and great-grandfather of Heracles.'
				ESQuery={
					_index='ks_ucs9_ci_interaction_index@'
					_type='Interaction'
					_source={Id='10024ODh48pdnzyg'}
					_id='10024ODh48pdnzyg'
					_score=2
				}
				TenantId=1
			}
		}
	}
	HasNext='FALSE';
}

Fuzzy Search

The following example of ContactListGet request made with LastName: Kittin and fuzziness:2 finds contacts Kittin and Kittins

Sample request and response

Request

Service=OMContacts
Method=ContactListGet
Type=Request
Parameters={
	TenantId=1
	ESQuery={
		"query":{
			"fuzzy":{
				"AttributeValues.LastName": {
					"value":"Kittin",
					"boost":1.0,
					"fuzziness": 2,
					"prefix_length": 0,
					"max_expansions":100
				}
			}
		}
	}
}

Response

Service=OMContacts
Method=ContactListGet
Type=Response
Parameters={ 
	PageSize=2
	ContactData={
		0={
			Id='10024ODh47sFZ5aE'
			Attributes={
				TenantId=1
				FirstName='Samantha';
				CreatedDate='2018-06-21T14:01:13.818Z'
				LastName='Kittin'
				ModifiedDate='2018-06-21T14:01:13.818Z'
				EmailAddress='sam.kittin@there.net'
			}
		}
		1={
			Id='10024ODh47sFVDQQ'
			Attributes={
				TenantId=1
				FirstName='Lee'
				CreatedDate='2018-06-21T14:01:13.736Z'
				LastName='Kittins'
				ModifiedDate='2018-06-21T14:01:13.736Z'
				EmailAddress='lee.kittins@there.net'
			}
		}
	}
	HasNext='FALSE';
}
 
This page was last modified on December 28, 2018, at 16:14.

Feedback

Comment on this article:

blog comments powered by Disqus