-
-
Save jhonata-menezes/d890d8a963d30b4b06a8d4855e2778c4 to your computer and use it in GitHub Desktop.
Analyzer para plural e acentos no elasticsearch
This file contains hidden or 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
//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 | |
}' |
This file contains hidden or 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
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