Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Bruno Flegler Dal'Col
Bruno Flegler Dal'Col

Posted on

     

#009: Como definir um template para um índice

No artigo anterior#008: Como definir o mapeamento no Elasticsearch definimos um mapping diretamente no índice, porém podemos criar um template e criar o índice a partir dele. Essa estratégia é útil quando criamos índices temporais.

PUT/_template/customers{"index_patterns":["customers_*"],"aliases":{"customers":{}},"mappings":{"properties":{"id":{"type":"text"},"age":{"type":"integer"},"email":{"type":"text"},"name":{"type":"text"},"createdAt":{"type":"date"}}}}
Enter fullscreen modeExit fullscreen mode

O campoindex_patterns será usado para corresponder aos nomes dos índices durante a criação. Exemplo:customers_2022_02,customers_2022_03, uma vez que o nome do índice corresponde ao patterncustomers_* o índice é criado com o mapping definido no template.

PUT/customers_2022_02
Enter fullscreen modeExit fullscreen mode
GET/customers_2022_02/_mapping{"customers_2022_02":{"mappings":{"properties":{"age":{"type":"integer"},"createdAt":{"type":"date"},"email":{"type":"text"},"id":{"type":"text"},"name":{"type":"text"}}}}}
Enter fullscreen modeExit fullscreen mode

O campoaliases também é bem útil quando queremos buscar em todos índices criados a partir do template. Exemplo:customers_2022_02,customers_2022_03, podemos pesquisar em ambos índices utilizando apenas o nomecustomers.

GET/customers/_search{"query":{"match_all":{}}}
Enter fullscreen modeExit fullscreen mode

Sua vez de praticar, te vejo em breve.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Entusiasta em Javascript, Node.js e Elasticsearch, com objetivo de se aperfeiçoar a cada dias mais técnicas e ferramentas nesse ecossistema.
  • Joined

More fromBruno Flegler Dal'Col

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp