usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject [28/31] incubator-usergrid git commit: Changes index declaration to be explicit on the index
Date Mon, 09 Mar 2015 15:25:41 GMT
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-405
Commit: bcc52284f0c2322d8cd219e71adc16f0f0385cfc
Parents: 5decb0d
Author: Todd Nine <tnine@apigee.com>
Authored: Mon Mar 9 00:08:15 2015 -0600
Committer: Todd Nine <tnine@apigee.com>
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;


Mime
View raw message