In this workshop we will spun elasticsearch and kibana using docker then knowing the basic functionality of elasticsearch.
Why we use docker because with docker we don't need to think about the installation depedency and many other stuff, docker just make it simple.
Some requirements that need to have, not should be exact you can always install the newest version but this is the condition of my machine:
- Docker (20.10)
- docker-compose (1.25.0)
Docker Images:
Basically you don't need to think much about this because when you run docker-compose up this image will automatically pull to your local machine
- elasticsearch:7.17.7
- kibana:7.17.7
- clone this repository
- run
docker-compose up
- goto localhost:5601
- choose Explore on my own
- choose menu (three line icon on top left) -> management -> dev tools
GET /_cat/indices
GET /_cat/indices?v
PUT /article1
GET /article1
DELETE /article1
PUT /article2/_settings
{
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": "1",
"max_gram": "50"
}
},
"analyzer": {
"autocomplete_analyzer": {
"filter": [
"lowercase",
"edgengram_filter"
],
"type": "custom",
"tokenizer": "whitespace"
}
}
}
}
PUT /character_filter_test
{
"settings": {
"analysis": {
"char_filter": {
"my_custom_char_filter": {
"type": "mapping",
"mappings": ["&=>and"]
}
},
"analyzer": {
"my_custom_analyzer": {
"tokenizer": "standard",
"char_filter": ["my_custom_char_filter"]
}
}
}
}
}
POST /character_filter_test/_analyze
{
"analyzer": "my_custom_analyzer",
"text": "Apples & Bananas"
}
PUT /tokenizer_test
{
"settings": {
"analysis": {
"tokenizer": {
"my_custom_tokenizer": {
"type": "whitespace"
}
}
}
}
}
POST /tokenizer_test/_analyze
{
"tokenizer": "my_custom_tokenizer",
"text": "Apples & Bananas"
}
PUT /token_filter_test
{
"settings": {
"analysis": {
"filter": {
"my_custom_token_filter": {
"type": "lowercase"
}
},
"analyzer": {
"my_custom_analyzer": {
"tokenizer": "standard",
"filter": ["my_custom_token_filter"]
}
}
}
}
}
POST /token_filter_test/_analyze
{
"analyzer": "my_custom_analyzer",
"text": "This is a SAMPLE & Text"
}
POST /_analyze
{
"analyzer": "standard",
"text": "This is a SAMPLE & Text"
}
POST /_analyze
{
"analyzer": "standard",
"text": "你好吗 - nihaoma"
}
POST /_analyze
{
"analyzer": "smartcn",
"text": "你好吗 - nihaoma"
}
POST /_analyze
{
"analyzer": "smartcn",
"text": "新冠肺炎疫情的现状 - current state of covid pandemic"
}
POST /_analyze
{
"analyzer": "standard",
"text": "新冠肺炎疫情的现状 - current state of covid pandemic"
}
POST /article2/_analyze
{
"analyzer": "autocomplete_analyzer",
"text": "新冠肺炎疫情的现状 - current state of covid pandemic"
}
docker ps # check the available running docker
docker exec -it docker_elasticsearch_1 bash # the second from the last is the name of container
# Install
/usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-smartcn
# Uninstall
/usr/share/elasticsearch/bin/elasticsearch-plugin remove analysis-smartcn
GET /_cat/plugins
- Keyword
Keyword is non analyzed type of data so elasticsearch will keep as is in the index (usefull for agregation and exact match) - Text
Text data will always analyzed if we not define the analyzer it will user standard analyzer - Number
For number data type - Boolean
For true or false data type - Datetime
For datetime data type
We can only add to current mapping, can't rename, delete if you want to rename or delete field you should recreate the mapping.
PUT /article2/_mapping
{
"properties": {
"title": {
"analyzer": "autocomplete_analyzer",
"fields": {
"keyword": {
"type": "keyword"
}
},
"type": "text"
},
"descripton": {
"fields": {
"keyword": {
"type": "keyword"
}
},
"type": "text"
},
"likes": {
"type": "long"
}
}
}
GET /article2/_mapping
PUT /article2
{
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": "1",
"max_gram": "50"
}
},
"analyzer": {
"autocomplete_analyzer": {
"filter": [
"lowercase",
"autocomplete_filter"
],
"type": "custom",
"tokenizer": "whitespace"
}
}
}
},
"mappings": {
"properties": {
"title": {
"analyzer": "autocomplete_analyzer",
"fields": {
"keyword": {
"type": "keyword"
}
},
"type": "text"
},
"descripton": {
"fields": {
"keyword": {
"type": "keyword"
}
},
"type": "text"
},
"likes": {
"type": "long"
}
}
}
}
GET /article2
POST article2/_doc
{
"title": "World War III Films",
"description": "Film that shows the situation of world war III",
"likes": 1000
}
POST article2/_doc
{
"title": "World War III Films",
"description": "Film that shows the situation of world war III"
}
POST article2/_doc/1
{
"title": "The Witcher III",
"description": "Game that use by most of reviewer to test the GPU or gaming performance",
"likes": 500
}
PUT article2/_doc/2
{
"title": "The Witcher III",
"description": "Game that use by most of reviewer to test the GPU or gaming performance"
}
GET /article2/_doc/<id_article>
GET article2/_doc/1
GET article2/_doc/2
PUT /article2/_doc/1
{
"title": "Resident Evil",
"description": "Another game that use by reviewer to test gamming performance"
}
POST article2/_update/1
{
"doc": {
"likes": 1200
}
}
DELETE article2/_doc/1
Elasticsearch will perform a search on all documents in the specified index and will return the top 10 results (default value for size parameter).
GET /article2/_search
GET /article2/_search
{
"query": {
"term": {
"title.keyword": "Resident Evil"
}
}
}
GET /article2/_search
{
"query": {
"term": {
"title.keyword": "resident evil"
}
}
}
GET /article2/_search
{
"query": {
"term": {
"title.keyword": {
"value": "resident evil",
"case_insensitive": true
}
}
}
}
PUT /article2/_doc/3
{
"title": "Primary Resident",
"description": "Primary Resident for living in the city"
}
PUT /article2/_doc/4
{
"title": "Resident Evil II",
"description": "Successor of the resident evil 1"
}
PUT /article2/_doc/5
{
"title": "Residual Agent",
"description": "Film about the living residence in the city"
}
PUT /article2/_doc/6
{
"title": "Resilience",
"description": "Book that tells us how to build resilience"
}
GET /article2/_search
{
"query": {
"term": {
"title": "resident"
}
}
}
GET /article2/_search
{
"query": {
"term": {
"title": "Resident"
}
}
}
GET /article2/_search
{
"query": {
"match": {
"title": {
"query": "Resident",
"analyzer": "standard"
}
}
}
}
GET /article2/_search
{
"query": {
"match": {
"description": "game living"
}
}
}
GET /article2/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"description": "game living"
}
}
],
"should": [
{
"match": {
"description": "city"
}
}
],
"must_not": [
{
"match": {
"title": "evil"
}
}
]
}
}
}
GET /article2/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "resident"
}
}
]
}
}
}
GET /article2/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "resident"
}
}
],
"should": [
{
"span_first": {
"match": {
"span_term": {
"title": "resident"
}
},
"end": 1
}
}
]
}
}
}
GET /article2/_search
{
"query": {
"match_phrase": {
"title": "resident evil"
}
}
}
GET /article2/_search
{
"query": {
"match": {
"title": "r"
}
}
}
GET /article2/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "r"
}
}
],
"should": [
{
"span_first": {
"match": {
"span_term": {
"title": "r"
}
},
"end": 2
}
}
]
}
}
}
GET /article2/_search
{
"query": {
"fuzzy": {
"description": {
"value": "citi",
"fuzziness": "AUTO"
}
}
}
}