Last active
September 1, 2020 16:26
-
-
Save dadoonet/d6757d15fa0726a83bb619ecd81153f7 to your computer and use it in GitHub Desktop.
Advanced Search for your Legacy application script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Step 0 : INIT | |
DELETE test | |
DELETE person | |
### Step 1 | |
GET / | |
GET _cat/indices/person*?v&h=index,docs.count,store.size | |
GET person/_search?track_total_hits=true | |
GET person/_mapping | |
### Step 2 : Play with analyzers | |
# What happens at index time? | |
POST person/_analyze | |
{ | |
"text": "JoE SMith", | |
"analyzer": "standard" | |
} | |
# What happens at search time? | |
POST person/_analyze | |
{ | |
"text": "JO", | |
"analyzer": "standard" | |
} | |
POST person/_analyze | |
{ | |
"text": "JOE", | |
"analyzer": "standard" | |
} | |
DELETE test | |
PUT test | |
{ | |
"settings": { | |
"analysis": { | |
"analyzer": { | |
"ngram": { | |
"tokenizer": "ngram_tokenizer" | |
} | |
}, | |
"tokenizer": { | |
"ngram_tokenizer": { | |
"type": "edge_ngram", | |
"min_gram": "1", | |
"max_gram": "10", | |
"token_chars": [ "letter", "digit" ] | |
} | |
} | |
} | |
} | |
} | |
# What happens at index time? | |
POST test/_analyze | |
{ | |
"text": "joe smith", | |
"analyzer": "ngram" | |
} | |
# What happens at search time? | |
POST test/_analyze | |
{ | |
"text": "JO", | |
"analyzer": "simple" | |
} | |
DELETE test | |
DELETE person | |
# We could manually run that | |
PUT person | |
{ | |
"settings": { | |
"analysis": { | |
"analyzer": { | |
"ngram": { | |
"tokenizer": "ngram_tokenizer", | |
"filter": [ | |
"lowercase" | |
] | |
} | |
}, | |
"tokenizer": { | |
"ngram_tokenizer": { | |
"type": "edge_ngram", | |
"min_gram": "1", | |
"max_gram": "10", | |
"token_chars": [ | |
"letter", | |
"digit" | |
] | |
} | |
} | |
} | |
}, | |
"mappings": { | |
"properties": { | |
"address": { | |
"properties": { | |
"city": { | |
"type": "text", | |
"fields": { | |
"ngram": { | |
"type": "text", | |
"analyzer": "ngram", | |
"search_analyzer": "simple" | |
}, | |
"keyword": { | |
"type": "keyword" | |
} | |
} | |
}, | |
"country": { | |
"type": "text", | |
"fields": { | |
"ngram": { | |
"type": "text", | |
"analyzer": "ngram", | |
"search_analyzer": "simple" | |
}, | |
"keyword": { | |
"type": "keyword" | |
} | |
} | |
}, | |
"countrycode": { | |
"type": "keyword" | |
}, | |
"location": { | |
"type": "geo_point" | |
}, | |
"zipcode": { | |
"type": "keyword" | |
} | |
} | |
}, | |
"children": { | |
"type": "long" | |
}, | |
"dateOfBirth": { | |
"type": "date", | |
"format": "yyyy-MM-dd||yyyy" | |
}, | |
"gender": { | |
"type": "text", | |
"fields": { | |
"ngram": { | |
"type": "text", | |
"analyzer": "ngram", | |
"search_analyzer": "simple" | |
}, | |
"keyword": { | |
"type": "keyword" | |
} | |
} | |
}, | |
"marketing": { | |
"properties": { | |
"cars": { | |
"type": "long" | |
}, | |
"electronic": { | |
"type": "long" | |
}, | |
"fashion": { | |
"type": "long" | |
}, | |
"food": { | |
"type": "long" | |
}, | |
"garden": { | |
"type": "long" | |
}, | |
"hifi": { | |
"type": "long" | |
}, | |
"music": { | |
"type": "long" | |
}, | |
"shoes": { | |
"type": "long" | |
}, | |
"toys": { | |
"type": "long" | |
} | |
} | |
}, | |
"name": { | |
"type": "text", | |
"fields": { | |
"ngram": { | |
"type": "text", | |
"analyzer": "ngram", | |
"search_analyzer": "simple" | |
} | |
} | |
}, | |
"reference": { | |
"type": "text" | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment