Skip to content

Instantly share code, notes, and snippets.

@eliasah
Last active April 4, 2023 11:39
Show Gist options
  • Save eliasah/02ff901d75f67a43f75e to your computer and use it in GitHub Desktop.
Save eliasah/02ff901d75f67a43f75e to your computer and use it in GitHub Desktop.
[elasticsearch] Ngram Tokenizer Test
#!/bin/bash
# This script demonstrates the usage of Elasticsearch's Ngram Tokenizer
curl -XDELETE localhost:9200/test?pretty=true
curl -XPUT localhost:9200/test?pretty=true -d '{
"settings":{
"analysis":{
"analyzer":{
"my_ngram_analyzer":{
"tokenizer":"my_ngram_tokenizer"
}
},
"tokenizer":{
"my_ngram_tokenizer":{
"type":"nGram",
"token_chars":[
"letter",
"digit"
]
}
}
}
}
}'
curl -XPUT localhost:9200/test/items/_mapping?pretty=true -d '{
"items":{
"properties":{
"accountId":{
"analyzer":"my_ngram_analyzer",
"type":"string"
},
"name":{
"type":"string"
}
}
}
}'
curl -XPUT http://localhost:9200/test/items/1?pretty=true -d '{accountId : "12341234", name:"Bob"}'
curl -XPUT http://localhost:9200/test/items/2?pretty=true -d '{accountId : "980987", name:"Marry"}'
curl -XPUT http://localhost:9200/test/items/3?pretty=true -d '{accountId : "234234", name:"Daniel"}'
# I ask the process to sleep so that the data can be available when queried
sleep 1
curl -XGET "http://localhost:9200/test/_search?pretty=true" -d'
{
"query": {
"query_string": {
"fields": ["accountId"],
"query": "4"
}
}
}'
@phungvanthuy26
Copy link

{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."
}
],
"type" : "illegal_argument_exception",
"reason" : "Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."
},
"status" : 400
}

i get an error with mapping,

@eliasah
Copy link
Author

eliasah commented Jan 1, 2022

@phungvanthuy26 this a very old gist (6 years) and I'm not sure for which elasticsearch version it is anymore. I'm afraid lots of stuff has changed since.

@phungvanthuy26
Copy link

@eliasah yes, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment