Skip to content

Instantly share code, notes, and snippets.

@thyagobr
Forked from luizgpsantos/Exemplo completo
Last active November 19, 2020 12:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thyagobr/e416f9d4dd273fc5463d to your computer and use it in GitHub Desktop.
Save thyagobr/e416f9d4dd273fc5463d to your computer and use it in GitHub Desktop.
//Cria o índice especificando quais os analyzer ele tem
//Além disso especifica que o campo "titulo" do tipo "seu_tipo" utiliza o analyzer recem criado
curl -XPUT "http://localhost:9200/my_index" -d'
{
"settings": {
"analysis": {
"analyzer": {
"analyzer_customizado": {
"tokenizer": "standard",
"filter": [
"lowercase",
"stemmer_plural_portugues",
"asciifolding"
]
}
},
"filter": {
"stemmer_plural_portugues": {
"type": "stemmer",
"name": "minimal_portuguese"
}
}
}
},
"mappings": {
"seu_tipo": {
"properties": {
"titulo": {
"type": "string",
"analyzer": "analyzer_customizado"
}
}
}
}
}'
//Indexa os seus documentos, que podem conter acentos, maiusculas, etc...
curl -XPUT "http://localhost:9200/my_index/seu_tipo/1" -d'
{
"titulo": "está ações lugares melhorias nível Nível"
}'
//Realiza uma busca por um termo sem acento, ç, etc...
curl -XPOST "http://localhost:9200/my_index/_search" -d'
{
"query": {
"match": {
"titulo": "esta acoes"
}
}
}'
//Outro exemplo de query...
curl -XPOST "http://localhost:9200/my_index/_search" -d'
{
"query": {
"match": {
"titulo": "nivel"
}
}
}'
// Isso daqui é usado só para endender como o seu analyzer está funcionando.
curl -XGET "http://localhost:9200/my_index/_analyze?analyzer=analyzer_customizado" -d'
{
está ações lugares melhorias nível Nível
}'
curl -XPUT "http://localhost:9200/my_index" -d'
{
"settings": {
"analysis": {
"analyzer": {
"analyzer_customizado": {
"tokenizer": "standard",
"filter": [
"lowercase",
"stemmer_plural_portugues",
"asciifolding"
]
}
},
"filter": {
"stemmer_plural_portugues": {
"type": "stemmer",
"name": "minimal_portuguese"
}
}
}
}
}'
curl -XGET "http://localhost:9200/my_index/_analyze?analyzer=analyzer_customizado" -d'
{
está ações lugares melhorias nível Nível
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment