Return-Path: X-Original-To: apmail-usergrid-commits-archive@minotaur.apache.org Delivered-To: apmail-usergrid-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F2A7B177EA for ; Mon, 9 Mar 2015 06:08:19 +0000 (UTC) Received: (qmail 51300 invoked by uid 500); 9 Mar 2015 06:08:19 -0000 Delivered-To: apmail-usergrid-commits-archive@usergrid.apache.org Received: (qmail 51274 invoked by uid 500); 9 Mar 2015 06:08:19 -0000 Mailing-List: contact commits-help@usergrid.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@usergrid.incubator.apache.org Delivered-To: mailing list commits@usergrid.incubator.apache.org Received: (qmail 51265 invoked by uid 99); 9 Mar 2015 06:08:19 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Mar 2015 06:08:19 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id AC212E10D1; Mon, 9 Mar 2015 06:08:19 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: toddnine@apache.org To: commits@usergrid.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: incubator-usergrid git commit: Changes index declaration to be explicit on the index Date: Mon, 9 Mar 2015 06:08:19 +0000 (UTC) Repository: incubator-usergrid Updated Branches: refs/heads/USERGRID-456 [created] bcc52284f Changes index declaration to be explicit on the index Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/bcc52284 Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/bcc52284 Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/bcc52284 Branch: refs/heads/USERGRID-456 Commit: bcc52284f0c2322d8cd219e71adc16f0f0385cfc Parents: 5decb0d Author: Todd Nine Authored: Mon Mar 9 00:08:15 2015 -0600 Committer: Todd Nine Committed: Mon Mar 9 00:08:15 2015 -0600 ---------------------------------------------------------------------- .../index/impl/EsEntityIndexImpl.java | 22 ++++++++++---------- .../persistence/index/impl/IndexingUtils.java | 5 +---- 2 files changed, 12 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bcc52284/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java index 80fede9..c9f5590 100644 --- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java @@ -50,6 +50,7 @@ import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksRequest; import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; +import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse; import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse; import org.elasticsearch.action.deletebyquery.IndexDeleteByQueryResponse; @@ -93,6 +94,7 @@ public class EsEntityIndexImpl implements AliasedEntityIndex { private static final Logger logger = LoggerFactory.getLogger( EsEntityIndexImpl.class ); private static final AtomicBoolean mappingsCreated = new AtomicBoolean( false ); + public static final String DEFAULT_TYPE = "_default_"; private final IndexIdentifier.IndexAlias alias; private final IndexIdentifier indexIdentifier; @@ -193,10 +195,6 @@ public class EsEntityIndexImpl implements AliasedEntityIndex { String normalizedSuffix = StringUtils.isNotEmpty(indexSuffix) ? indexSuffix : null; try { - if (!mappingsCreated.getAndSet(true)) { - createMappings(); - } - //get index name with suffix attached String indexName = indexIdentifier.getIndex(normalizedSuffix); @@ -217,6 +215,9 @@ public class EsEntityIndexImpl implements AliasedEntityIndex { .actionGet(); timeNewIndexCreation.stop(); + //create the mappings + createMappings( indexName ); + //ONLY add the alias if we create the index, otherwise we're going to overwrite production settings /** @@ -225,6 +226,7 @@ public class EsEntityIndexImpl implements AliasedEntityIndex { //We do NOT want to create an alias if the index already exists, we'll overwrite the indexes that //may have been set via other administrative endpoint + addAlias(normalizedSuffix); testNewIndex(); @@ -354,18 +356,16 @@ public class EsEntityIndexImpl implements AliasedEntityIndex { * Setup ElasticSearch type mappings as a template that applies to all new indexes. * Applies to all indexes that* start with our prefix. */ - private void createMappings() throws IOException { + private void createMappings(final String indexName) throws IOException { XContentBuilder xcb = IndexingUtils.createDoubleStringIndexMapping( - XContentFactory.jsonBuilder(), "_default_"); + XContentFactory.jsonBuilder(), DEFAULT_TYPE ); + //Added For Graphite Metrics Timer.Context timePutIndex = mappingTimer.time(); - PutIndexTemplateResponse pitr = esProvider.getClient().admin().indices() - .preparePutTemplate("usergrid_template") - // set mapping as the default for all types - .setTemplate(config.getIndexPrefix() + "*").addMapping( "_default_", xcb ) - .execute().actionGet(); + PutMappingResponse pitr = esProvider.getClient().admin().indices().preparePutMapping( indexName ).setType( + DEFAULT_TYPE ).setSource( xcb ).execute().actionGet(); timePutIndex.stop(); if ( !pitr.isAcknowledged() ) { throw new IndexException( "Unable to create default mappings" ); http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bcc52284/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java index 14dca3e..be0c96c 100644 --- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java @@ -151,9 +151,8 @@ public class IndexingUtils { .startObject() - .startObject(type) /** add routing "_routing":{ "required":false, "path":"ug_entityId" **/ - .startObject("_routing").field("required",true).field("path",ENTITYID_ID_FIELDNAME).endObject() + //.startObject("_routing").field("required",true).field("path",ENTITYID_ID_FIELDNAME).endObject() .startArray("dynamic_templates") // we need most specific mappings first since it's a stop on match algorithm @@ -224,8 +223,6 @@ public class IndexingUtils { .endArray() - .endObject() - .endObject(); return builder;