ElasticSearch 7 Common Calls
GET Version Info
GET {{ _.url }}/
{
"name": "iad1esapp2vz894",
"cluster_name": "02d8af3b06f26098d2adc80fdeeab14a",
"cluster_uuid": "pAEzGLJ9RVG1vaBiohStGw",
"version": {
"number": "7.2.1",
"build_flavor": "oss",
"build_type": "tar",
"build_hash": "fe6cb20",
"build_date": "2019-07-24T17:58:29.979462Z",
"build_snapshot": false,
"lucene_version": "8.0.0",
"minimum_wire_compatibility_version": "6.8.0",
"minimum_index_compatibility_version": "6.0.0-beta1"
},
"tagline": "You Know, for Search"
}
GET Index Settings
Settings are where analyzers and tokenizers are defined. This one includes a custom ngram tokenezer.
GET {{ _.url }}/{{ _.index }}/_settings
{
"searchable_content_dev": {
"settings": {
"index": {
"mapping": {
"total_fields": {
"limit": "10000"
}
},
"number_of_shards": "1",
"provided_name": "searchable_content_dev",
"creation_date": "1632918278107",
"analysis": {
"analyzer": {
"lb_analyzer": {
"tokenizer": "lb_tokenizer"
},
"nodash": {
"type": "custom",
"tokenizer": "whitespace"
}
},
"tokenizer": {
"lb_tokenizer": {
"token_chars": [
"letter",
"digit"
],
"min_gram": "3",
"type": "ngram",
"max_gram": "4"
}
}
},
"number_of_replicas": "1",
"uuid": "lUzzMvlORi6NbWqsI0NmHQ",
"version": {
"created": "7020199"
}
}
}
}
}
GET Index Mapping
The Mapping is how fields in content are getting indexed and mapped to analyzers.
GET {{ _.url }}/{{ _.index }}/_mapping
{
"searchable_content_dev": {
"mappings": {
"properties": {
"content": {
"properties": {
"affirmation": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"artisanStory": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"description": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
...
POST Analyzer Test
You can submit text through an analyzer to see how it will break it down for search.
POST {{ _.url }}/{{ _.index }}/_analyze
{
"analyzer": "lb_analyzer",
"text": "bees"
}
ngram based example:
{
"tokens": [
{
"token": "bee",
"start_offset": 0,
"end_offset": 3,
"type": "word",
"position": 0
},
{
"token": "bees",
"start_offset": 0,
"end_offset": 4,
"type": "word",
"position": 1
},
{
"token": "ees",
"start_offset": 1,
"end_offset": 4,
"type": "word",
"position": 2
}
]
}
Get a Document by ID
GET {{ _.url }}/{{ _.index }}/_doc/19982
{
"_index": "searchable_content",
"_type": "_doc",
"_id": "19982",
"_version": 1,
"_seq_no": 4780,
"_primary_term": 1,
"found": true,
"_source": {
"type": "general",
"siteSearchFeatured": 0,
"siteSearchShow": 1,
"content": {
"fullURL": "\/campaign\/2021\/send-a-lama-to-school-story",
"navigationAnchor": "send-a-lama-to-school",
"sharedContentTitle": "Send A Lama To School Story",
"sharedContentCopy": "Every lama deserves an education, and your support makes it happen.",
"metaDescription": "Every lama deserves an education, and your support makes it happen.",
"title": "Send A Lama To School Story",
"description": "Every lama deserves an education, and your support makes it happen.",
"body": "Send a Lama to School\nEvery lama deserves an education, and your support makes it happen."
},
"displayData": {
"url": "\/campaign\/2021\/send-a-lama-to-school-story.html",
"image": null,
"title": "",
"description": "",
"group": "general",
"featured": 0
}
}
}
Get Docs where Field EXISTS
POST {{ _.url }}/{{ _.index }}/_search
{
"query": {
"exists": {
"field": "content.wysiwyg"
}
}
}
Get Docs where Field DOES NOT EXIST
POST {{ _.url }}/{{ _.index }}/_search
{
"query": {
"bool": {
"must_not": {
"exists": {
"field": "content.body"
}
}
}
}
}
Search with Weight Boosting
A collection of function_scoring
can boost how relevancy is scored for specific fields.
POST {{ _.url }}/{{ _.index }}/_search
{
"from": 0,
"size": 15,
"query": {
"function_score": {
"query": {
"bool": {
"must": [
{
"match": {
"siteSearchShow": "1"
}
},
{
"match": {
"siteSearchFeatured": "0"
}
},
{
"multi_match": {
"query": "{{ _.q }}",
"fields": [
"content.headerTitle",
"content.sharedContentTitle",
"content.productDescription",
"content.description",
"content.sharedContentCopy",
"content.title"
]
}
}
]
}
},
"boost": 5,
"functions": [
{
"filter": {
"match": {
"content.headerTitle": "{{ _.q }}"
}
},
"random_score": [],
"weight": 6
},
{
"filter": {
"match": {
"content.sharedContentTitle": "{{ _.q }}"
}
},
"random_score": [],
"weight": 6
},
{
"filter": {
"match": {
"content.productDescription": "{{ _.q }}"
}
},
"random_score": [],
"weight": 6
},
{
"filter": {
"match": {
"content.description": "{{ _.q }}"
}
},
"random_score": [],
"weight": 6
},
{
"filter": {
"match": {
"content.sharedContentCopy": "{{ _.q }}"
}
},
"random_score": [],
"weight": 6
},
{
"filter": {
"match": {
"type": "lamas-and-donations"
}
},
"random_score": [],
"weight": 10
}
]
}
}
}