Package com.dotcms.repackage.org.elasticsearch.client

Examples of com.dotcms.repackage.org.elasticsearch.client.Client


      if(content==null || !UtilMethods.isSet(content.getIdentifier())) return;

      Runnable indexAction=new Runnable() {
            public void run() {
                try {
                    Client client=new ESClient().getClient();
                    BulkRequestBuilder req = (bulk==null) ? client.prepareBulk() : bulk;

                    // http://jira.dotmarketing.net/browse/DOTCMS-6886
                    // check for related content to reindex
                    List<Contentlet> contentToIndex=new ArrayList<Contentlet>();
                    contentToIndex.add(content);
View Full Code Here


  private void removeContentFromIndex(final Contentlet content, final boolean onlyLive, final List<Relationship> relationships) throws DotHibernateException {
     Runnable indexRunner = new Runnable() {
              public void run() {
                try {
                    String id=content.getIdentifier()+"_"+content.getLanguageId();
                    Client client=new ESClient().getClient();
                    BulkRequestBuilder bulk=client.prepareBulk();
                    IndiciesInfo info=APILocator.getIndiciesAPI().loadIndicies();

                    bulk.add(client.prepareDelete(info.live, "content", id));
                    if(info.reindex_live!=null)
                        bulk.add(client.prepareDelete(info.reindex_live, "content", id));

                    if(!onlyLive) {

                        // here we search for relationship fields pointing to this
                        // content to be deleted. Those contentlets are reindexed
                        // to avoid left those fields making noise in the index
                        for(Relationship rel : relationships) {
                            String q = "";
                            boolean isSameStructRelationship = rel.getParentStructureInode().equalsIgnoreCase(rel.getChildStructureInode());

                            if(isSameStructRelationship)
                                q = "+type:content +(" + rel.getRelationTypeValue() + "-parent:" + content.getIdentifier() + " " +
                                    rel.getRelationTypeValue() + "-child:" + content.getIdentifier() + ") ";
                            else
                                q = "+type:content +" + rel.getRelationTypeValue() + ":" + content.getIdentifier();

                            List<Contentlet> related = APILocator.getContentletAPI().search(q, -1, 0, null, APILocator.getUserAPI().getSystemUser(), false);
                            indexContentletList(bulk, related, false);
                        }

                        bulk.add(client.prepareDelete(info.working, "content", id));
                        if(info.reindex_working!=null)
                            bulk.add(client.prepareDelete(info.reindex_working, "content", id));
                    }

                      bulk.execute().actionGet();

                }
View Full Code Here

    /**
     * Returns a list of dotcms working and live indices.
     * @return
     */
    public List<String> listDotCMSIndices() {
        Client client=new ESClient().getClient();
        Map<String,IndexStatus> indices=APILocator.getESIndexAPI().getIndicesAndStatus();
        List<String> indexNames=new ArrayList<String>();

        for(String idx : indices.keySet())
            if(isDotCMSIndexName(idx))
                indexNames.add(idx);

        List<String> existingIndex=new ArrayList<String>();
        for(String idx : indexNames)
            if(client.admin().indices().exists(new IndicesExistsRequest(idx)).actionGet().isExists())
                existingIndex.add(idx);
        indexNames=existingIndex;

        List<String> indexes = new ArrayList<String>();
        indexes.addAll(indexNames);
View Full Code Here

    /**
     * returns all indicies and status
     * @return
     */
    public Map<String,IndexStatus> getIndicesAndStatus() {
        Client client=new ESClient().getClient();
        return client.admin().indices().status(new IndicesStatusRequest()).actionGet().getIndices();
    }
View Full Code Here

        toFile.mkdirs();
      }
      toFile = new File(ConfigUtils.getBackupPath() + File.separator + index + "_" + date + ".json");
    }

    Client client = esclient.getClient();

    BufferedWriter bw = null;
    try {
        ZipOutputStream zipOut=new ZipOutputStream(new FileOutputStream(toFile));
        zipOut.setLevel(9);
        zipOut.putNextEntry(new ZipEntry(toFile.getName()));

      bw = new BufferedWriter(
              new OutputStreamWriter(zipOut), 500000); // 500K buffer

      final String type=index.startsWith("sitesearch_") ? SiteSearchAPI.ES_SITE_SEARCH_MAPPING : "content";
          final String mapping = mappingAPI.getMapping(index, type);
          bw.write(MAPPING_MARKER);
          bw.write(mapping);
          bw.newLine();

          // setting up the search for all content
      SearchResponse scrollResp = client.prepareSearch(index).setSearchType(SearchType.SCAN).setQuery(QueryBuilders.matchAllQuery())
          .setSize(100).setScroll(TimeValue.timeValueMinutes(2)).execute().actionGet();
      while (true) {
        scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(TimeValue.timeValueMinutes(2)).execute()
            .actionGet();
        boolean hitsRead = false;
        for (SearchHit hit : scrollResp.getHits()) {
          bw.write(hit.getId());
          bw.write(JSON_RECORD_DELIMITER);
View Full Code Here

    BufferedReader br = null;

    boolean indexExists = indexExists(index);

    Client client = new ESClient().getClient();

    try {
      if (!indexExists) {
        final IndicesAdminClient iac = new ESClient().getClient().admin().indices();

        createIndex(index);
      }

      ZipInputStream zipIn=new ZipInputStream(new FileInputStream(backupFile));
      zipIn.getNextEntry();
      br = new BufferedReader(
              new InputStreamReader(zipIn),500000);

      // setting number_of_replicas=0 to improve the indexing while restoring
      // also we restrict the index to the current server
      moveIndexToLocalNode(index);

      // wait a bit for the changes be made
      Thread.sleep(1000L);

      // setting up mapping
      String mapping=br.readLine();
      boolean mappingExists=mapping.startsWith(MAPPING_MARKER);
      String type="content";
      if(mappingExists) {

          String patternStr = "^"+MAPPING_MARKER+"\\s*\\{\\s*\"(\\w+)\"";
          Pattern pattern = Pattern.compile(patternStr);
          Matcher matcher = pattern.matcher(mapping);
          boolean matchFound = matcher.find();
          if (matchFound)
              type = matcher.group(1);
      }

      // reading content
      ArrayList<String> jsons = new ArrayList<String>();

      // we recover the line that wasn't a mapping so it should be content
      if(!mappingExists)
          jsons.add(mapping);

      for (int x = 0; x < 10000000; x++) {
        for (int i = 0; i < 100; i++)
          while (br.ready())
            jsons.add(br.readLine());

        if (jsons.size() > 0) {
            try {
                BulkRequestBuilder req = client.prepareBulk();
                for (String raw : jsons) {
                  int delimidx=raw.indexOf(JSON_RECORD_DELIMITER);
                  if(delimidx>0) {
                    String id = raw.substring(0, delimidx);
                    String json = raw.substring(delimidx + JSON_RECORD_DELIMITER.length(), raw.length());
View Full Code Here

  /**
   * List of all indicies
   * @return
   */
  public  Set<String> listIndices() {
    Client client = esclient.getClient();
    Map<String, IndexStatus> indices = client.admin().indices().status(new IndicesStatusRequest()).actionGet().getIndices();
    return indices.keySet();
  }
View Full Code Here

   * unclusters an index, including changing the routing to all local
   * @param index
   * @throws IOException
   */
  public  void moveIndexToLocalNode(String index) throws IOException {
        Client client=new ESClient().getClient();
//        String nodeName="dotCMS_" + Config.getStringProperty("DIST_INDEXATION_SERVER_ID");
        String nodeName="dotCMS_" + APILocator.getServerAPI().readServerId();
        UpdateSettingsResponse resp=client.admin().indices().updateSettings(
          new UpdateSettingsRequest(index).settings(
                jsonBuilder().startObject()
                     .startObject("index")
                        .field("number_of_replicas",0)
                        .field("routing.allocation.include._name",nodeName)
View Full Code Here

   * clusters an index, including changing the routing
   * @param index
   * @throws IOException
   */
    public  void moveIndexBackToCluster(String index) throws IOException {
        Client client=new ESClient().getClient();
        int nreplicas=Config.getIntProperty("es.index.number_of_replicas",0);
        UpdateSettingsResponse resp=client.admin().indices().updateSettings(
          new UpdateSettingsRequest(index).settings(
                jsonBuilder().startObject()
                     .startObject("index")
                        .field("number_of_replicas",nreplicas)
                        .field("routing.allocation.include._name","*")
 
View Full Code Here

    AdminLogger.log(this.getClass(), "updateReplicas", "Replicas updated to index: " + indexName);
    }

    public void putToIndex(String idx, String json, String id){
     try{
       Client client=new ESClient().getClient();

       IndexResponse response = client.prepareIndex(idx, SiteSearchAPI.ES_SITE_SEARCH_MAPPING, id)
              .setSource(json)
              .execute()
              .actionGet();

    } catch (Exception e) {
View Full Code Here

TOP

Related Classes of com.dotcms.repackage.org.elasticsearch.client.Client

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.