Skip to content

Instantly share code, notes, and snippets.

@dadoonet
Last active July 11, 2023 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dadoonet/f911291c4dd19b0802031db3064c648f to your computer and use it in GitHub Desktop.
Save dadoonet/f911291c4dd19b0802031db3064c648f to your computer and use it in GitHub Desktop.
Demo script for BBLs
DELETE mon_index
DELETE person
GET /
#### 1ST PART CRUD
DELETE person
# Create the first doc
PUT person/_doc/david
{
"name" : "David Pilato"
}
GET person/_doc/david
# Update the doc
PUT person/_doc/david
{
"name" : "David Pilato",
"address" : {
"city": "Cergy"
}
}
GET person/_doc/david
# Remove the doc
DELETE person/_doc/david
GET person/_doc/david
# Create some documents (like 10)
POST person/_doc/
{
"name" : "David Pilato",
"comments": "Ici c'est Cergy"
}
# Create some documents (like 3)
POST person/_doc/
{
"name" : "David Pilato",
"comments": "Ici c'est Cergy Pontoise"
}
# Create one or 2 docs
POST person/_doc/
{
"name" : "David Pilato",
"comments": "Ici c'est Pontoise"
}
#### SEARCH
# Search all (and from/size)
GET person/_search
GET person/_search
{
"query": {
"match": {
"comments": "cergy"
}
}
}
GET person/_search
{
"query": {
"match": {
"comments": "CERGY!"
}
}
}
GET person/_search
{
"query": {
"match": {
"comments": "Cergy Pontoise"
}
}
}
#### 2nd Part: INJECTOR
# Inject data
# Run aggregations
# Play in Kibana
# Show monitoring
# Scale Out
DELETE person
GET person/_search?track_total_hits=true
# Back To Slides
#### 3RD PART ANALYZE
POST _analyze
{
"text": [ "The quick brown fox jumps over the lazy Dog!" ]
}
POST _analyze
{
"analyzer": "english",
"text": [ "The quick brown fox jumps over the lazy Dog!" ]
}
# Start with ... And add the other filters
POST _analyze
{
"tokenizer": "standard",
"filter": [
],
"text": [ "L'éléphant est ROSE et il trompe énormément !" ]
}
POST _analyze
{
"explain": true,
"tokenizer": "standard",
"filter": [
"lowercase",
{"type": "stop", "stopwords": [ "_french_" ]},
{"type": "elision", "articles" : ["l", "m", "t", "qu", "n", "s", "j"]},
"asciifolding" ,
{"type": "stemmer", "name": "light_french"}
],
"text": [ "L'éléphant est ROSE et il trompe énormément !" ]
}
POST _analyze
{
"analyzer": "french",
"text": [ "L'éléphant est ROSE et il trompe énormément !" ]
}
## Not so light
POST _analyze
{
"tokenizer": "standard",
"filter": [
"lowercase",
{"type": "stop", "stopwords": [ "_french_" ]},
{"type": "elision", "articles" : ["l", "m", "t", "qu", "n", "s", "j"]},
"asciifolding" ,
{"type": "stemmer", "name": "french"}
],
"text": [ "L'éléphant est ROSE et il trompe énormément !" ]
}
POST _analyze
{
"tokenizer": "standard",
"filter": [
"lowercase",
{"type": "stop", "stopwords": [ "_french_" ]},
{"type": "elision", "articles" : ["l", "m", "t", "qu", "n", "s", "j"]},
"asciifolding" ,
{"type": "stemmer", "name": "french"}
],
"text": [ "Des éléphantes" ]
}
## Bizarre ?
POST _analyze
{
"analyzer": "french",
"text": [ "Un avion" ]
}
POST _analyze
{
"analyzer": "french",
"text": [ "Des avions" ]
}
## Ngrams
POST _analyze
{
"tokenizer": "standard",
"filter": [
{"type": "edge_ngram", "min_gram" : 2, "max_gram" : 5}
],
"text": [ "eleph" ]
}
POST _analyze
{
"tokenizer": "standard",
"filter": [
{"type": "ngram", "min_gram" : 2, "max_gram" : 3}
],
"text": [ "eleph" ]
}
DELETE mon_index
PUT mon_index
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0,
"analysis": {
"analyzer": {
"francais": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"stop_francais",
"fr_stemmer",
"asciifolding",
"elision"
]
},
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"elision",
"lowercase",
"asciifolding",
"autocomplete"
]
}
},
"filter": {
"stop_francais": {
"type": "stop",
"stopwords": [
"_french_",
"twitter"
]
},
"fr_stemmer": {
"type": "stemmer",
"name": "french"
},
"elision": {
"type": "elision",
"articles": [
"l",
"m",
"t",
"qu",
"n",
"s",
"j",
"d",
"lorsqu"
]
},
"autocomplete": {
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 5
}
}
}
},
"mappings": {
"properties": {
"description": {
"type": "text",
"analyzer": "francais"
},
"username": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "simple"
},
"city": {
"type": "text",
"analyzer": "francais",
"fields": {
"autocomplete": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "simple"
},
"keyword": {
"type": "keyword"
}
}
}
}
}
}
POST mon_index/_analyze
{
"text": [ "Cergy", "Cénac" ],
"analyzer": "autocomplete"
}
POST mon_index/_analyze
{
"text": [ "Cer" ],
"analyzer": "autocomplete"
}
POST mon_index/_analyze
{
"text": [ "Cer" ],
"analyzer": "simple"
}
POST mon_index/_analyze
{
"text": [ "J'habite à Cergy" ],
"analyzer": "francais"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment