Search Template 目标:解耦程序和搜索DSL

    • 创建模板:

      1. POST _scripts/<templateid>
      2. {
      3. "script": {
      4. "lang": "mustache",
      5. "source": {
      6. "query": {
      7. "match": {
      8. "title": "{{query_string}}"
      9. }
      10. }
      11. }
      12. }
      13. }
      1. POST _scripts/tmdb
      2. {
      3. "script":{
      4. "lang": "mustache",
      5. "source": {
      6. "_source":["firstname","lastname","email"]
      7. },
      8. "query":{
      9. "multi_match": {
      10. "query": "{{q}}",
      11. "fields": ["firstname","lastname","email"]
      12. }
      13. }
      14. }
      15. }
    • 查看:GET _scripts/tmdb

    • 调用:POST tmdb/_search/template{ "id": "tmdb", "params": { "q": "strong" }}

    Index Alias:实现零停机运维

    1. POST _aliases
    2. {
    3. "actions": [
    4. {
    5. "add": {
    6. "index": "accounts",
    7. "alias": "accountData"
    8. }
    9. },
    10. {
    11. "remove": {
    12. "index": "address",
    13. "alias": "addressData"
    14. }
    15. }
    16. ]
    17. }