예제 #1
0
  protected void initializeIndex() {
    String index = this.getIndexName();

    IndicesExistsResponse indexExistsResponse = client.prepareIndicesExist(index).get();
    try {

      if (!indexExistsResponse.isExists()) {
        LOG.debug("Setup of {} for type {}", this.getIndexName(), this.getIndexType());
        client.prepareCreate(index).setSettings(getIndexSettings()).get();
      }

      LOG.debug("Update of index {} for type {}", this.getIndexName(), this.getIndexType());
      client
          .preparePutMapping(index)
          .setType(getIndexType())
          .setIgnoreConflicts(true)
          .setSource(mapDomain())
          .get();

    } catch (Exception e) {
      throw new IllegalStateException("Invalid configuration for index " + this.getIndexName(), e);
    }
  }