7.3. Elasticsearch の操作¶
7.3.1. インデックステンプレートの登録¶
「 IM-BPM 仕様書 」-「 IM-BPM Elasticsearch インデックステンプレート例 」をコピーし、/var/tmp/im_bpm_index_template.jsonとして保存してください。ファイルの保存後、cURLなどのツールを用いて、下記のコマンドを実行し、ElasticsearchのRestAPIを呼び出し、インデックステンプレートを登録してください。# curl -XPUT http://localhost:9200/_template/im_bpm-index_template -H 'Content-Type: application/json' -d @/var/tmp/im_bpm_index_template.json下記のような応答が返却されれば、インデックステンプレートの登録は完了です。{"acknowledged":true}
コラム
KibanaからElasticsearchへインデックスのテンプレートを登録する方法に関して
Elasticsearchには、Kibanaというデータ可視化などを行えるツールが存在します。
- Kibana : https://www.elastic.co/products/kibana (English)
 
Kibanaの環境をすでに構築済みの場合、Kibanaの「Dev Tools」機能を使用して、Elasticsearchへインデックスのテンプレートを登録することも出来ます。
Kibanaの「メインメニュー」→「Dev Tools」→「Console」タブのテキストエリアに下記のコマンドを貼り付け、実行を行ってください。
この方法は他のElasticsearchコマンドの実行についても同様に行うことが可能です。
(以下の例はテナントIDがdefaultの場合のテンプレートの登録方法です)
PUT _template/im_bpm-index_template
{
  "index_patterns": "im_bpm-default-*",
  "mappings": {
    "im_bpm": {
      "properties" : {
        "type_activiti" : {
          "type" : "keyword"
        },
        "time" : {
          "type" : "date",
          "format" : "dateOptionalTime"
        },
        "user_cd" : {
          "type" : "keyword"
        },
        "user_name" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "process_definition_id" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "process_instance_id" : {
          "type" : "keyword"
        },
        "execution_id" : {
          "type" : "keyword"
        },
        "activity_id" : {
          "type" : "keyword"
        },
        "activity_name" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "activity_type" : {
          "type" : "keyword"
        },
        "behavior_class" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "activity_cause" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "activity_cause_activity_impl" : {
          "properties" : {
            "id" : {
              "type" : "keyword"
            },
            "async" : {
              "type" : "boolean"
            },
            "exclusive" : {
              "type" : "boolean"
            },
            "height" : {
              "type" : "long"
            },
            "scope" : {
              "type" : "boolean"
            },
            "width" : {
              "type" : "long"
            },
            "x" : {
              "type" : "long"
            },
            "y" : {
              "type" : "long"
            }
          }
        },
        "activity_cause_event_subscription_entity" : {
          "properties" : {
            "activity" : {
              "properties" : {
                "id" : {
                  "type" : "keyword"
                },
                "async" : {
                  "type" : "boolean"
                },
                "exclusive" : {
                  "type" : "boolean"
                },
                "height" : {
                  "type" : "long"
                },
                "scope" : {
                  "type" : "boolean"
                },
                "width" : {
                  "type" : "long"
                },
                "x" : {
                  "type" : "long"
                },
                "y" : {
                  "type" : "long"
                }
              }
            },
            "activityId" : {
              "type" : "keyword"
            },
            "created" : {
              "type" :   "date",
              "format" : "epoch_millis"
            },
            "eventName" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "eventType" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "executionId" : {
              "type" : "keyword"
            },
            "id" : {
              "type" : "keyword"
            },
            "processDefinitionId" : {
              "type" : "keyword"
            },
            "processInstanceId" : {
              "type" : "keyword"
            },
            "revision" : {
              "type" : "long"
            },
            "tenantId" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            }
          }
        },
        "activity_cause_job_entity" : {
          "properties" : {
            "duedate" : {
              "type" :   "date",
              "format" : "epoch_millis"
            },
            "exclusive" : {
              "type" : "boolean"
            },
            "executionId" : {
              "type" : "keyword"
            },
            "id" : {
              "type" : "keyword"
            },
            "jobHandlerConfiguration" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "jobHandlerType" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "jobType" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "processDefinitionId" : {
              "type" : "keyword"
            },
            "processInstanceId" : {
              "type" : "keyword"
            },
            "retries" : {
              "type" : "long"
            },
            "revision" : {
              "type" : "long"
            },
            "tenantId" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            }
          }
        },
        "error_code" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "message_name" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "message_data" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "signal_name" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "signal_data" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "activity_duration" : {
          "type" : "long"
        },
        "nested_process_definition_id" : {
          "type" : "keyword"
        },
        "nested_process_instance_id" : {
          "type" : "keyword"
        },
        "process_cause" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "process_cause_activity_impl" : {
          "properties" : {
            "id" : {
              "type" : "keyword"
            },
            "async" : {
              "type" : "boolean"
            },
            "exclusive" : {
              "type" : "boolean"
            },
            "height" : {
              "type" : "long"
            },
            "scope" : {
              "type" : "boolean"
            },
            "width" : {
              "type" : "long"
            },
            "x" : {
              "type" : "long"
            },
            "y" : {
              "type" : "long"
            }
          }
        },
        "process_cause_event_subscription_entity" : {
          "properties" : {
            "activity" : {
              "properties" : {
                "id" : {
                  "type" : "keyword"
                },
                "async" : {
                  "type" : "boolean"
                },
                "exclusive" : {
                  "type" : "boolean"
                },
                "failedJobRetryTimeCycleValue" : {
                  "type" : "text",
                  "fields" : {
                    "raw" : {
                      "type" :  "keyword"
                    }
                  }
                },
                "height" : {
                  "type" : "long"
                },
                "scope" : {
                  "type" : "boolean"
                },
                "width" : {
                  "type" : "long"
                },
                "x" : {
                  "type" : "long"
                },
                "y" : {
                  "type" : "long"
                }
              }
            },
            "activityId" : {
              "type" : "keyword"
            },
            "configuration" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "created" : {
              "type" :   "date",
              "format" : "epoch_millis"
            },
            "eventName" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "eventType" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "executionId" : {
              "type" : "keyword"
            },
            "id" : {
              "type" : "keyword"
            },
            "processDefinitionId" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "processInstanceId" : {
              "type" : "keyword"
            },
            "revision" : {
              "type" : "long"
            },
            "tenantId" : {
              "type" : "keyword"
            }
          }
        },
        "process_cause_job_entity" : {
          "properties" : {
            "duedate" : {
              "type" :   "date",
              "format" : "epoch_millis"
            },
            "exceptionMessage" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "exclusive" : {
              "type" : "boolean"
            },
            "executionId" : {
              "type" : "keyword"
            },
            "id" : {
              "type" : "keyword"
            },
            "jobHandlerConfiguration" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "jobHandlerType" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "jobType" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "lockExpirationTime" : {
              "type" :   "date",
              "format" : "epoch_millis"
            },
            "lockOwner" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "processDefinitionId" : {
              "type" : "keyword"
            },
            "processInstanceId" : {
              "type" : "keyword"
            },
            "retries" : {
              "type" : "long"
            },
            "revision" : {
              "type" : "long"
            },
            "tenantId" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            }
          }
        },
        "process_duration" : {
          "type" : "long"
        },
        "sequence_flow_id" : {
          "type" : "text"
        },
        "source_activity_id" : {
          "type" : "keyword"
        },
        "source_activity_name" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "source_activity_type" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "source_activity_behavior_class" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "target_activity_id" : {
          "type" : "keyword"
        },
        "target_activity_name" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "target_activity_type" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "target_activity_behavior_class" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "task_id" : {
          "type" : "keyword"
        },
        "task_name" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "task_definition_key" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "description" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "assignee" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "owner" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "category" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "due_date" : {
          "type" : "date",
          "format" : "dateOptionalTime"
        },
        "form_key" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "priority" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "task_duration" : {
          "type" : "long"
        }
      }
    }
  }
}
7.3.2. インデックステンプレートの削除¶
cURLなどを用いて下記のコマンドを実行し、ElasticsearchのRestAPIを呼び出し、インデックステンプレートの削除を行ってください。# curl -XDELETE http://localhost:9200/_template/im_bpm-index_template下記のような応答が返却されれば、インデックステンプレートの削除は完了です。{"acknowledged":true}コラム
インデックステンプレートを削除しても、既に作成されてしまっているインデックスには影響はありません。
7.3.3. インデックスの作成¶
Elasticsearchでは、ドキュメントが登録される際に、自動的にインデックスが作成されますが、以下のようにcURLなどのツールを用いて、RestAPIを呼び出すことにより、手動でインデックスの作成を行うこともできます。# curl -XPUT http://localhost:9200/im_bpm-index/
7.3.4. インデックスの更新¶
Elasticsearchでは、以下のようにcURLなどのツールを用いて、RestAPIを呼び出すことにより、インデックスの設定を更新できます。# curl -XPUT http://localhost:9200/im_bpm-index/_settings -H 'Content-Type: application/json' -d' { "index": { "number_of_replicas": "4" } }'注意
インデックス作成後はプライマリシャードの数は変更できません。
7.3.5. インデックスの削除¶
Elasticsearchでは、以下のようにcURLなどのツールを用いて、RestAPIを呼び出すことにより、インデックスを削除できます。# curl -XDELETE http://localhost:9200/im_bpm-index注意
インデックスの削除の際、実行確認などは行われません。インデックスの削除を行う場合は、十分な検討を行ってください。