You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2015/03/18 22:59:52 UTC

[1/5] incubator-usergrid git commit: latest

Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-480 [created] 89f2c2f1f


latest


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/98bc9a42
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/98bc9a42
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/98bc9a42

Branch: refs/heads/USERGRID-480
Commit: 98bc9a4254f23cc07d437a1e818fa9438c0d04f7
Parents: b53cb07
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Mar 17 21:13:32 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Mar 17 21:13:32 2015 -0600

----------------------------------------------------------------------
 .../index/impl/EsEntityIndexBatchImpl.java      |  27 ++---
 .../index/impl/EsEntityIndexImpl.java           |  20 ++--
 .../persistence/index/impl/EsQueryVistor.java   |  88 +++++++++-------
 .../persistence/index/impl/IndexingUtils.java   | 104 +++++++++++--------
 4 files changed, 135 insertions(+), 104 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/98bc9a42/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
index 92312d2..34e7702 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
@@ -56,15 +56,7 @@ import com.codahale.metrics.Timer;
 import rx.Observable;
 import rx.functions.Func1;
 
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.ANALYZED_STRING_PREFIX;
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.BOOLEAN_PREFIX;
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.ENTITYID_ID_FIELDNAME;
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.ENTITY_CONTEXT_FIELDNAME;
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.GEO_PREFIX;
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.NUMBER_PREFIX;
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.STRING_PREFIX;
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.createContextName;
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.createIndexDocId;
+import static org.apache.usergrid.persistence.index.impl.IndexingUtils.*;
 
 
 public class EsEntityIndexBatchImpl implements EntityIndexBatch {
@@ -243,7 +235,7 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
 
             if ( f instanceof ListField ) {
                 List list = ( List ) field.getValue();
-                entityMap.put( field.getName().toLowerCase(),
+                entityMap.put( ARRAY_PREFIX+ field.getName().toLowerCase(),
                         new ArrayList( processCollectionForMap( list ) ) );
 
                 if ( !list.isEmpty() ) {
@@ -255,7 +247,7 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
             }
             else if ( f instanceof ArrayField ) {
                 List list = ( List ) field.getValue();
-                entityMap.put( field.getName().toLowerCase(),
+                entityMap.put( ARRAY_PREFIX+ field.getName().toLowerCase(),
                         new ArrayList( processCollectionForMap( list ) ) );
             }
             else if ( f instanceof SetField ) {
@@ -265,7 +257,7 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
             }
             else if ( f instanceof EntityObjectField ) {
                 EntityObject eo = ( EntityObject ) field.getValue();
-                entityMap.put( field.getName().toLowerCase(), entityToMap( eo ) ); // recursion
+                entityMap.put( field.getName().toLowerCase(), entityToMap(eo) ); // recursion
             }
             else if ( f instanceof StringField ) {
 
@@ -284,12 +276,11 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
                 locMap.put( "lon", locField.getValue().getLongitude() );
                 entityMap.put( GEO_PREFIX + field.getName().toLowerCase(), locMap );
             }
-            else if (  f instanceof DoubleField
-                    || f instanceof FloatField
-                    || f instanceof IntegerField
-                    || f instanceof LongField ) {
-
-                entityMap.put( NUMBER_PREFIX + field.getName().toLowerCase(), field.getValue() );
+            else if( f instanceof DoubleField || f instanceof  FloatField){
+                entityMap.put( DOUBLE_PREFIX + field.getName().toLowerCase(), field.getValue() );
+            }
+            else if( f instanceof LongField || f instanceof IntegerField){
+                entityMap.put( LONG_PREFIX + field.getName().toLowerCase(), field.getValue() );
             }
             else if ( f instanceof BooleanField ) {
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/98bc9a42/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 16f4b3f..598c8d9 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
@@ -457,11 +457,19 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
 
                 logger.debug( "   Sort: {} order by {}", stringFieldName, order.toString() );
 
-                final String numberFieldName = NUMBER_PREFIX + sp.getPropertyName();
-                final FieldSortBuilder numberSort = SortBuilders.fieldSort( numberFieldName )
+                final String longFieldName = LONG_PREFIX + sp.getPropertyName();
+                final FieldSortBuilder longSort = SortBuilders.fieldSort( longFieldName )
                         .order( order ).ignoreUnmapped( true );
-                srb.addSort( numberSort );
-                logger.debug( "   Sort: {} order by {}", numberFieldName, order.toString() );
+                srb.addSort( longSort );
+                logger.debug( "   Sort: {} order by {}", longFieldName, order.toString() );
+
+
+                final String doubleFieldName = DOUBLE_PREFIX + sp.getPropertyName();
+                final FieldSortBuilder doubleSort = SortBuilders.fieldSort( doubleFieldName )
+                    .order( order ).ignoreUnmapped( true );
+                srb.addSort( doubleSort );
+                logger.debug( "   Sort: {} order by {}", doubleFieldName, order.toString() );
+
 
                 final String booleanFieldName = BOOLEAN_PREFIX + sp.getPropertyName();
                 final FieldSortBuilder booleanSort = SortBuilders.fieldSort( booleanFieldName )
@@ -613,7 +621,7 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
             }
         };
 
-        doInRetry( retryOperation );
+        doInRetry(retryOperation);
     }
 
 
@@ -741,7 +749,7 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
                new ClusterHealthRequest( new String[] { indexIdentifier.getIndex( null ) } ) );
 
             //only wait 2 seconds max
-            ClusterHealthResponse chr = future.actionGet( 2000 );
+            ClusterHealthResponse chr = future.actionGet(2000);
             return Health.valueOf( chr.getStatus().name() );
         }
         catch ( Exception ex ) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/98bc9a42/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
index f012bab..8e8b43c 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
@@ -50,15 +50,11 @@ import org.apache.usergrid.persistence.index.query.tree.WithinOperand;
 
 import com.google.common.base.Joiner;
 
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.ANALYZED_STRING_PREFIX;
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.BOOLEAN_PREFIX;
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.GEO_PREFIX;
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.NUMBER_PREFIX;
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.STRING_PREFIX;
+import static org.apache.usergrid.persistence.index.impl.IndexingUtils.*;
 
 
 /**
- * Visits tree of  parsed Query operands and populates 
+ * Visits tree of  parsed Query operands and populates
  * ElasticSearch QueryBuilder that represents the query.
  */
 public class EsQueryVistor implements QueryVisitor {
@@ -67,7 +63,7 @@ public class EsQueryVistor implements QueryVisitor {
     Stack<QueryBuilder> stack = new Stack<QueryBuilder>();
     List<FilterBuilder> filterBuilders = new ArrayList<FilterBuilder>();
 
-    
+
     @Override
     public void visit( AndOperand op ) throws IndexException {
 
@@ -157,14 +153,14 @@ public class EsQueryVistor implements QueryVisitor {
         Object value = op.getLiteral().getValue();
 
         BoolQueryBuilder qb = QueryBuilders.boolQuery(); // let's do a boolean OR
-        qb.minimumNumberShouldMatch(1); 
+        qb.minimumNumberShouldMatch(1);
 
         // field is an entity/array that needs no name prefix
         qb = qb.should( QueryBuilders.matchQuery( name, value ) );
 
         // OR field is a string and needs the prefix on the name
         qb = qb.should( QueryBuilders.matchQuery( addPrefix( value.toString(), name, true), value));
-        
+
         stack.push( qb );
     }
 
@@ -186,7 +182,7 @@ public class EsQueryVistor implements QueryVisitor {
         FilterBuilder fb = FilterBuilders.geoDistanceFilter( name )
            .lat( lat ).lon( lon ).distance( distance, DistanceUnit.METERS );
         filterBuilders.add( fb );
-    } 
+    }
 
 
     @Override
@@ -222,19 +218,19 @@ public class EsQueryVistor implements QueryVisitor {
             qb.minimumNumberShouldMatch(1);
 
             // field is an entity/array that does not need a prefix on its name
-            // TODO is this right now that we've updated our doc structure?  
+            // TODO is this right now that we've updated our doc structure?
             // Should this be "must" instead of should?
             qb = qb.should( QueryBuilders.wildcardQuery( name, svalue ) );
-           
+
             // or field is just a string that does need a prefix
             if ( svalue.indexOf("*") != -1 ) {
                 qb = qb.should( QueryBuilders.wildcardQuery( addPrefix( value, name ), svalue ) );
             } else {
                 qb = qb.should( QueryBuilders.termQuery(     addPrefix( value, name ), value ));
-            } 
+            }
             stack.push( qb );
             return;
-        } 
+        }
 
         // assume all other types need prefix
         stack.push( QueryBuilders.termQuery( addPrefix( value, name ), value ));
@@ -276,29 +272,38 @@ public class EsQueryVistor implements QueryVisitor {
         if ( parts.length > 1 ) {
             name = parts[ parts.length - 1 ];
         }
-        
+
         if ( value instanceof String && analyzed ) {
             name = addAnalyzedStringPrefix( name );
 
         } else if ( value instanceof String ) {
             name = addStringPrefix( name );
 
-        } else if ( value instanceof Number ) {
-            name = addNumberPrefix( name );
+        }else if ( value instanceof Integer ) {
+            name = addLongPrefix(name);
+
+        }else if ( value instanceof Long ) {
+            name = addLongPrefix(name);
+
+        } else if ( value instanceof Float ) {
+            name = addDoublePrefix(name);
+
+        }else if ( value instanceof Float ) {
+            name = addDoublePrefix(name);
 
         } else if ( value instanceof Boolean ) {
-            name = addBooleanPrefix( name );
+            name = addBooleanPrefix(name);
 
         } else if ( value instanceof UUID ) {
-            name = addStringPrefix( name );
+            name = addStringPrefix(name);
         }
 
-        // re-create nested property name 
+        // re-create nested property name
         if ( parts.length > 1 ) {
             parts[parts.length - 1] = name;
             Joiner joiner = Joiner.on(".").skipNulls();
             return joiner.join(parts);
-        } 
+        }
 
         return name;
     }
@@ -307,34 +312,41 @@ public class EsQueryVistor implements QueryVisitor {
     private String addAnalyzedStringPrefix( String name ) {
         if ( name.startsWith( ANALYZED_STRING_PREFIX ) ) {
             return name;
-        }  
+        }
         return ANALYZED_STRING_PREFIX + name;
-    } 
-   
+    }
+
 
     private String addStringPrefix( String name ) {
         if ( name.startsWith( STRING_PREFIX ) ) {
             return name;
-        } 
+        }
         return STRING_PREFIX + name;
-    } 
-   
+    }
 
-    private String addNumberPrefix( String name ) {
-        if ( name.startsWith( NUMBER_PREFIX ) ) {
+
+    private String addDoublePrefix( String name ) {
+        if ( name.startsWith( DOUBLE_PREFIX ) ) {
             return name;
-        } 
-        return NUMBER_PREFIX + name;
-    } 
-   
+        }
+        return DOUBLE_PREFIX + name;
+    }
+
+    private String addLongPrefix( String name ) {
+        if ( name.startsWith( LONG_PREFIX ) ) {
+            return name;
+        }
+        return LONG_PREFIX + name;
+    }
+
 
     private String addBooleanPrefix( String name ) {
         if ( name.startsWith( BOOLEAN_PREFIX ) ) {
             return name;
-        } 
+        }
         return BOOLEAN_PREFIX + name;
-    } 
-   
+    }
+
 
     @Override
     public QueryBuilder getQueryBuilder() {
@@ -354,10 +366,10 @@ public class EsQueryVistor implements QueryVisitor {
 			for ( FilterBuilder fb : filterBuilders ) {
 				if ( andFilter == null ) {
 					andFilter = FilterBuilders.andFilter( fb );
-				} else {	
+				} else {
 					andFilter = FilterBuilders.andFilter( andFilter, fb );
 				}
-			}	
+			}
 
 		} else if ( !filterBuilders.isEmpty() ) {
 			return filterBuilders.get(0);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/98bc9a42/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 ffd98e9..0df3a2c 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
@@ -35,8 +35,11 @@ public class IndexingUtils {
     public static final String STRING_PREFIX = "su_";
     public static final String ANALYZED_STRING_PREFIX = "sa_";
     public static final String GEO_PREFIX = "go_";
-    public static final String NUMBER_PREFIX = "nu_";
+    public static final String LONG_PREFIX = "long_";
+    public static final String DOUBLE_PREFIX = "long_";
+
     public static final String BOOLEAN_PREFIX = "bu_";
+    public static final String ARRAY_PREFIX = "ar_";
 
     public static final String SPLITTER = "\\__";
 
@@ -54,6 +57,7 @@ public class IndexingUtils {
 
     public static final String ENTITY_VERSION_FIELDNAME = "ug_entityVersion";
 
+    public static final String DOC_VALUES_KEY = "doc_values";
 
     /**
       * Create our sub scope.  This is the ownerUUID + type
@@ -151,78 +155,94 @@ public class IndexingUtils {
 
             .startObject()
 
-                    /**  add routing  "_routing":{ "required":false,  "path":"ug_entityId" **/
-                     .startObject("_routing").field("required",true).field("path",ENTITYID_ID_FIELDNAME).endObject()
-                     .startArray("dynamic_templates")
+                    /**  add routing  "_routing":{ "required":true,  "path":"ug_entityId" **/
+                    .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
-
                         .startObject()
-
-                            .startObject( "entity_id_template" )
-                                .field( "match", IndexingUtils.ENTITYID_ID_FIELDNAME )
-                                    .field( "match_mapping_type", "string" )
-                                            .startObject( "mapping" ).field( "type", "string" )
-                                                .field( "index", "not_analyzed" )
+                            .startObject("entity_id_template")
+                                .field("match", IndexingUtils.ENTITYID_ID_FIELDNAME)
+                                    .field("match_mapping_type", "string")
+                                            .startObject("mapping").field("type", "string")
+                                                .field("index", "not_analyzed")
                                             .endObject()
                                     .endObject()
                                 .endObject()
 
                             .startObject()
-                            .startObject( "entity_context_template" )
-                                .field( "match", IndexingUtils.ENTITY_CONTEXT_FIELDNAME )
-                                .field( "match_mapping_type", "string" )
-                                    .startObject( "mapping" )
-                                        .field( "type", "string" )
-                                        .field( "index", "not_analyzed" ).endObject()
-                                    .endObject()
+                                .startObject("entity_context_template")
+                                    .field("match", IndexingUtils.ENTITY_CONTEXT_FIELDNAME)
+                                    .field("match_mapping_type", "string")
+                                        .startObject("mapping")
+                                            .field("type", "string")
+                                            .field("index", "not_analyzed")
+                                        .endObject()
+                                .endObject()
                             .endObject()
 
                             .startObject()
-                            .startObject( "entity_version_template" )
-                                .field( "match", IndexingUtils.ENTITY_VERSION_FIELDNAME )
-                                        .field( "match_mapping_type", "string" )
-                                            .startObject( "mapping" ).field( "type", "long" )
-                                            .endObject()
-                                        .endObject()
+                                .startObject("entity_version_template")
+                                    .field("match", IndexingUtils.ENTITY_VERSION_FIELDNAME)
+                                    .field("match_mapping_type", "string")
+                                    .startObject("mapping").field("type", "long").field(DOC_VALUES_KEY, true)
                                     .endObject()
+                                .endObject()
+                            .endObject()
 
                             // any string with field name that starts with sa_ gets analyzed
                             .startObject()
-                                .startObject( "template_1" )
-                                    .field( "match", ANALYZED_STRING_PREFIX + "*" )
-                                    .field( "match_mapping_type", "string" ).startObject( "mapping" )
-                                    .field( "type", "string" )
-                                    .field( "index", "analyzed" )
+                                .startObject("template_string_analyzed")
+                                    .field("match", ANALYZED_STRING_PREFIX + "*")
+                                    .field("match_mapping_type", "string")
+                                    .startObject("mapping")
+                                        .field("type", "string")
+                                        .field("index", "analyzed")
+                                    .endObject()
                                 .endObject()
                             .endObject()
 
-                        .endObject()
-
                         // all other strings are not analyzed
                         .startObject()
-                            .startObject( "template_2" )
+                            .startObject("template_string_not_analyzed")
                                 //todo, should be string prefix, remove 2 field mapping
-                                .field( "match", "*" )
-                                .field( "match_mapping_type", "string" )
-                                .startObject( "mapping" )
-                                    .field( "type", "string" )
-                                        .field( "index", "not_analyzed" )
+                                .field("match", "*")
+                                .field("match_mapping_type", "string")
+                                .startObject("mapping")
+                                    .field("type", "string")
+                                    .field("index", "not_analyzed")
                                 .endObject()
                             .endObject()
                         .endObject()
 
                         // fields names starting with go_ get geo-indexed
                         .startObject()
-                            .startObject( "template_3" )
-                                .field( "match", GEO_PREFIX + "location" )
-                                    .startObject( "mapping" )
-            .field( "type", "geo_point" )
+                            .startObject("template_geo")
+                                .field("match", GEO_PREFIX + "location")
+                                    .startObject("mapping").field("type", "geo_point")
                                     .endObject()
                             .endObject()
                         .endObject()
+                            // all other strings are not analyzed
+                        .startObject()
+                            .startObject("template__long")
+                                .field("match", LONG_PREFIX + "*")
+                                .field("match_mapping_type", "long")
+                                .startObject("mapping").field("type", "long").field("index","not_analyzed").field(DOC_VALUES_KEY, true).endObject()
+                            .endObject()
+                        .endObject()
 
-                    .endArray()
+                        .startObject()
+                            .startObject("template__double")
+                                .field("match", DOUBLE_PREFIX + "*")
+                                .field("match_mapping_type", "double")
+                                .startObject("mapping").field("type", "double").field("index", "not_analyzed").field(DOC_VALUES_KEY, true).endObject()
+                            .endObject()
+                        .endObject()
 
+                    .endArray()
             .endObject();
 
         return builder;


[3/5] incubator-usergrid git commit: single index

Posted by sf...@apache.org.
single 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/346eba98
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/346eba98
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/346eba98

Branch: refs/heads/USERGRID-480
Commit: 346eba98ed1080940730fb617951e6172a1683bb
Parents: 1199e47
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Mar 18 14:56:36 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Mar 18 14:56:36 2015 -0600

----------------------------------------------------------------------
 .../corepersistence/CpEntityManagerFactory.java |  3 -
 .../usergrid/persistence/index/EntityIndex.java | 21 ------
 .../persistence/index/IndexIdentifier.java      | 16 +----
 .../usergrid/persistence/index/SearchTypes.java | 14 +++-
 .../index/impl/EsEntityIndexBatchImpl.java      |  6 +-
 .../index/impl/EsEntityIndexImpl.java           | 69 +++++---------------
 .../persistence/index/impl/IndexingUtils.java   |  8 ++-
 .../persistence/index/impl/EntityIndexTest.java | 65 +-----------------
 8 files changed, 42 insertions(+), 160 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/346eba98/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index fe4d828..2bdb54c 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -292,7 +292,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         EntityManager appEm = getEntityManager( applicationId );
 
         appEm.create( applicationId, TYPE_APPLICATION, properties );
-        appEm.createIndex();
         appEm.resetRoles();
         appEm.refreshIndex();
 
@@ -706,7 +705,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         EntityManager em = getEntityManager( appId );
 
         //explicitly invoke create index, we don't know if it exists or not in ES during a rebuild.
-        em.createIndex();
         Application app = em.getApplication();
 
         em.reindex( po );
@@ -760,7 +758,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         EntityManager em = getEntityManager( appId );
 
         //explicitly invoke create index, we don't know if it exists or not in ES during a rebuild.
-        em.createIndex();
         Application app = em.getApplication();
 
         em.reindexCollection( po, collectionName, reverse );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/346eba98/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
index aa2bf8e..c8840fa 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
@@ -68,27 +68,6 @@ public interface EntityIndex {
     public CandidateResults search(final IndexScope indexScope, final SearchTypes searchType, Query query );
 
     /**
-     * Get the candidate results of all versions of the entity for this id.
-     * @param indexScope The scope of the index to search in
-     * @param id The id to search within.
-     */
-    public CandidateResults getEntityVersions(final IndexScope indexScope, final Id id);
-
-//    /**
-//     * Create a delete method that deletes by Id. This will delete all documents from ES with the same entity Id,
-//     * effectively removing all versions of an entity from all index scopes
-//     * @param entityId The entityId to remove
-//     */
-//    public Future deleteAllVersionsOfEntity(final Id entityId );
-//
-//    /**
-//     * Takes all the previous versions of the current entity and deletes all previous versions
-//     * @param id The id to remove
-//     * @param version The max version to retain
-//     */
-//    public Future deletePreviousVersions(final Id id, final UUID version);
-
-    /**
      * Refresh the index.
      */
     public void refresh();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/346eba98/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java
index f23dc36..8465d84 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java
@@ -40,7 +40,7 @@ public class IndexIdentifier{
      * @return
      */
     public IndexAlias getAlias() {
-        return new IndexAlias(config,getIndexBase());
+        return new IndexAlias(config,config.getIndexPrefix());
     }
 
     /**
@@ -50,22 +50,12 @@ public class IndexIdentifier{
      */
     public String getIndex(String suffix) {
         if (suffix != null) {
-            return getIndexBase() + "_" + suffix;
+            return config.getIndexPrefix() + "_" + suffix;
         } else {
-            return getIndexBase();
+            return config.getIndexPrefix();
         }
     }
 
-    /**
-     * returns the base name for index which will be used to add an alias and index
-     * @return
-     */
-    private String getIndexBase() {
-        StringBuilder sb = new StringBuilder();
-        sb.append(config.getIndexPrefix()).append(IndexingUtils.SEPARATOR);
-        IndexingUtils.idString(sb, applicationScope.getApplication());
-        return sb.toString();
-    }
 
     public class IndexAlias{
         private final String readAlias;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/346eba98/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchTypes.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchTypes.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchTypes.java
index 35b3a8b..1a97da2 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchTypes.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchTypes.java
@@ -20,6 +20,10 @@ package org.apache.usergrid.persistence.index;/*
  */
 
 
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.index.impl.IndexingUtils;
+import org.apache.usergrid.persistence.model.entity.Id;
+
 import java.util.Arrays;
 
 
@@ -37,11 +41,17 @@ public class SearchTypes {
     private SearchTypes( final String... types ) {this.types = types;}
 
 
-    public String[] getTypeNames() {
-        return types;
+    public String[] getTypeNames(ApplicationScope applicationScope) {
+        String[] typeNames = new String[types.length];
+        int i =0 ;
+        for(String type : types){
+            typeNames[i++] = IndexingUtils.getType(applicationScope,type);
+        }
+        return typeNames;
     }
 
 
+
     /**
      * Create a search that will search on the specified types
      * @param types

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/346eba98/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
index 23b9041..977fe51 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
@@ -117,9 +117,7 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
         String indexId = createIndexDocId( entity, context );
 
         log.debug( "Indexing entity documentId {} data {} ", indexId, entityAsMap );
-        final String entityType = entity.getId().getType();
-
-
+        final String entityType =IndexingUtils.getType(applicationScope, entity.getId());
         container.addIndexRequest(new IndexRequest(alias.getWriteAlias(), entityType, indexId, entityAsMap));
 
         return this;
@@ -134,7 +132,7 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
         ValidationUtils.verifyVersion( version );
 
         final String context = createContextName(indexScope);
-        final String entityType = id.getType();
+        final String entityType =IndexingUtils.getType(applicationScope, id);
 
         final String indexId = createIndexDocId( id, version, context );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/346eba98/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 598c8d9..110b320 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
@@ -199,9 +199,9 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
         final int numberOfShards = config.getNumberOfShards();
         final int numberOfReplicas = config.getNumberOfReplicas();
         String[] indexes = getIndexesFromEs(AliasType.Write);
-        if(indexes == null || indexes.length==0) {
+//        if(indexes == null || indexes.length==0) {
             addIndex(null, numberOfShards, numberOfReplicas, config.getWriteConsistencyLevel());
-        }
+//        }
     }
 
     @Override
@@ -233,21 +233,21 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
 
                 //ONLY add the alias if we create the index, otherwise we're going to overwrite production settings
 
-                /**
-                 * DO NOT MOVE THIS LINE OF CODE UNLESS YOU REALLY KNOW WHAT YOU'RE DOING!!!!
-                 */
-
-                //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();
 
                 logger.info("Created new Index Name [{}] ACK=[{}]", indexName, cir.isAcknowledged());
             } catch (IndexAlreadyExistsException e) {
                 logger.info("Index Name [{}] already exists", indexName);
             }
+            /**
+             * DO NOT MOVE THIS LINE OF CODE UNLESS YOU REALLY KNOW WHAT YOU'RE DOING!!!!
+             */
+
+            //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();
 
 
 
@@ -347,7 +347,7 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
         // to receive documents. Occasionally we see errors.
         // See this post: http://s.apache.org/index-missing-exception
 
-        logger.debug( "Testing new index name: read {} write {}", alias.getReadAlias(), alias.getWriteAlias());
+        logger.debug("Testing new index name: read {} write {}", alias.getReadAlias(), alias.getWriteAlias());
 
         final RetryOperation retryOperation = new RetryOperation() {
             @Override
@@ -410,12 +410,9 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
     public CandidateResults search(final IndexScope indexScope, final SearchTypes searchTypes,
             final Query query ) {
 
-        final String context = IndexingUtils.createContextName( indexScope );
-        final String[] entityTypes = searchTypes.getTypeNames();
-
+        final String context = IndexingUtils.createContextName(indexScope);
+        final String[] entityTypes = searchTypes.getTypeNames(applicationScope);
         QueryBuilder qb = query.createQueryBuilder(context);
-
-
         SearchResponse searchResponse;
 
         if ( query.getCursor() == null ) {
@@ -635,42 +632,6 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
     }
 
 
-    @Override
-    public CandidateResults getEntityVersions( final IndexScope scope, final Id id ) {
-
-        //since we don't have paging inputs, there's no point in executing a query for paging.
-
-        final String context = IndexingUtils.createContextName(scope);
-        final SearchTypes searchTypes = SearchTypes.fromTypes(id.getType());
-
-        final QueryBuilder queryBuilder =
-                QueryBuilders.termQuery( IndexingUtils.ENTITY_CONTEXT_FIELDNAME, context );
-
-        final SearchRequestBuilder srb = esProvider.getClient().prepareSearch( alias.getReadAlias() )
-                .setTypes(searchTypes.getTypeNames())
-                .setScroll(cursorTimeout + "m")
-                .setQuery(queryBuilder);
-
-        final SearchResponse searchResponse;
-        try {
-            //Added For Graphite Metrics
-            Timer.Context timeEntityIndex = getVersionsTimer.time();
-            searchResponse = srb.execute().actionGet();
-            timeEntityIndex.stop();
-        }
-        catch ( Throwable t ) {
-            logger.error( "Unable to communicate with elasticsearch" );
-            failureMonitor.fail( "Unable to execute batch", t);
-            throw t;
-        }
-
-
-        failureMonitor.success();
-
-        return parseResults(searchResponse, new Query());
-    }
-
-
 
     /**
      * Completely delete an index.

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/346eba98/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 0df3a2c..aa6d0f3 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
@@ -230,7 +230,7 @@ public class IndexingUtils {
                             .startObject("template__long")
                                 .field("match", LONG_PREFIX + "*")
                                 .field("match_mapping_type", "long")
-                                .startObject("mapping").field("type", "long").field("index","not_analyzed").field(DOC_VALUES_KEY, true).endObject()
+                                .startObject("mapping").field("type", "long").field("index", "not_analyzed").field(DOC_VALUES_KEY, true).endObject()
                             .endObject()
                         .endObject()
 
@@ -249,5 +249,11 @@ public class IndexingUtils {
     }
 
 
+    public static String getType(ApplicationScope applicationScope, Id entityId) {
+        return getType(applicationScope,entityId.getType());
+    }
 
+    public static String getType(ApplicationScope applicationScope, String type) {
+        return idString(applicationScope.getApplication()) + SEPARATOR + type;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/346eba98/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
index ca9bf79..22ca51f 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
@@ -271,7 +271,7 @@ public class EntityIndexTest extends BaseIT {
         ObjectMapper mapper = new ObjectMapper();
         List<Object> sampleJson = mapper.readValue( is, new TypeReference<List<Object>>() {} );
         EntityIndexBatch batch = entityIndex.createBatch();
-        insertJsonBlob(sampleJson,batch, entityType, indexScope, max,startIndex);
+        insertJsonBlob(sampleJson,batch, entityType, indexScope, max, startIndex);
         batch.execute().get();
         entityIndex.refresh();
     }
@@ -297,10 +297,9 @@ public class EntityIndexTest extends BaseIT {
             EntityUtils.setVersion(entity, UUIDGenerator.newTimeUUID());
             entity.setField(new UUIDField(IndexingUtils.ENTITYID_ID_FIELDNAME, UUID.randomUUID()));
             batch.index(indexScope, entity);
+            batch.execute().get();
+
 
-            if(count %1000 == 0){
-                batch.execute().get();
-            }
             if ( ++count > max ) {
                 break;
             }
@@ -370,7 +369,6 @@ public class EntityIndexTest extends BaseIT {
 
     private void testQueries(final IndexScope scope, SearchTypes searchTypes, final EntityIndex entityIndex ) {
 
-
         testQuery(scope, searchTypes, entityIndex, "name = 'Morgan Pierce'", 1 );
 
         testQuery(scope, searchTypes, entityIndex, "name = 'morgan pierce'", 1 );
@@ -443,63 +441,6 @@ public class EntityIndexTest extends BaseIT {
         }
     }
 
-
-    @Test
-    public void getEntityVersions() throws Exception {
-
-        Id appId = new SimpleId( "application" );
-        Id ownerId = new SimpleId( "owner" );
-
-        ApplicationScope applicationScope = new ApplicationScopeImpl( appId );
-
-        IndexScope indexScope = new IndexScopeImpl( ownerId, "users" );
-
-
-
-        EntityIndex entityIndex = eif.createEntityIndex( applicationScope );
-        entityIndex.initializeIndex();
-
-        final String middleName = "middleName" + UUIDUtils.newTimeUUID();
-        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-        properties.put( "username", "edanuff" );
-        properties.put( "email", "ed@anuff.com" );
-        properties.put( "middlename", middleName );
-
-        Map entityMap = new HashMap() {{
-            put( "username", "edanuff" );
-            put( "email", "ed@anuff.com" );
-            put( "middlename", middleName );
-        }};
-
-        final Id userId = new SimpleId("user");
-
-        Entity user = EntityIndexMapUtils.fromMap( entityMap );
-        EntityUtils.setId( user, userId);
-        EntityUtils.setVersion( user, UUIDGenerator.newTimeUUID() );
-
-
-        final EntityIndexBatch batch = entityIndex.createBatch();
-        user.setField(new UUIDField(IndexingUtils.ENTITYID_ID_FIELDNAME, UUID.randomUUID()));
-
-        batch.index( indexScope, user );
-
-        user.setField( new StringField( "address1", "1782 address st" ) );
-        batch.index( indexScope, user );
-        user.setField( new StringField( "address2", "apt 508" ) );
-        batch.index( indexScope,  user );
-        user.setField( new StringField( "address3", "apt 508" ) );
-        batch.index( indexScope,  user);
-        batch.execute().get();
-        entityIndex.refresh();
-
-        CandidateResults results = entityIndex.getEntityVersions(indexScope,  user.getId() );
-
-        assertEquals(1,  results.size());
-        assertEquals( results.get( 0 ).getId(), user.getId() );
-        assertEquals( results.get(0).getVersion(), user.getVersion());
-    }
-
-
     @Test
     public void deleteVerification() throws Throwable {
 


[2/5] incubator-usergrid git commit: rollback array fix

Posted by sf...@apache.org.
rollback array fix


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/1199e477
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/1199e477
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/1199e477

Branch: refs/heads/USERGRID-480
Commit: 1199e477e7336a8aebfdef67f2ea8f2d9407c54a
Parents: 98bc9a4
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Mar 18 11:23:08 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Mar 18 11:23:08 2015 -0600

----------------------------------------------------------------------
 .../usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1199e477/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
index 34e7702..23b9041 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
@@ -235,7 +235,7 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
 
             if ( f instanceof ListField ) {
                 List list = ( List ) field.getValue();
-                entityMap.put( ARRAY_PREFIX+ field.getName().toLowerCase(),
+                entityMap.put( field.getName().toLowerCase(),
                         new ArrayList( processCollectionForMap( list ) ) );
 
                 if ( !list.isEmpty() ) {
@@ -247,7 +247,7 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
             }
             else if ( f instanceof ArrayField ) {
                 List list = ( List ) field.getValue();
-                entityMap.put( ARRAY_PREFIX+ field.getName().toLowerCase(),
+                entityMap.put( field.getName().toLowerCase(),
                         new ArrayList( processCollectionForMap( list ) ) );
             }
             else if ( f instanceof SetField ) {


[4/5] incubator-usergrid git commit: index tests pass

Posted by sf...@apache.org.
index tests pass


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/947f0632
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/947f0632
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/947f0632

Branch: refs/heads/USERGRID-480
Commit: 947f063269cda28c1bb25d55d732adb5c419d5b1
Parents: 346eba9
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Mar 18 15:53:54 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Mar 18 15:53:54 2015 -0600

----------------------------------------------------------------------
 .../usergrid/persistence/index/SearchType.java  | 49 ++++++++++++++++++++
 .../index/impl/EsEntityIndexBatchImpl.java      |  9 ++--
 .../index/impl/EsEntityIndexImpl.java           |  4 +-
 .../persistence/index/impl/EntityIndexTest.java |  2 +-
 4 files changed, 56 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/947f0632/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchType.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchType.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchType.java
new file mode 100644
index 0000000..5501c09
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchType.java
@@ -0,0 +1,49 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  *  contributor license agreements.  The ASF licenses this file to You
+ *  * under the Apache License, Version 2.0 (the "License"); you may not
+ *  * use this file except in compliance with the License.
+ *  * You may obtain a copy of the License at
+ *  *
+ *  *     http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * Unless required by applicable law or agreed to in writing, software
+ *  * distributed under the License is distributed on an "AS IS" BASIS,
+ *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  * See the License for the specific language governing permissions and
+ *  * limitations under the License.  For additional information regarding
+ *  * copyright in this work, please see the NOTICE file in the top level
+ *  * directory of this distribution.
+ *
+ */
+package org.apache.usergrid.persistence.index;
+
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.index.impl.IndexingUtils;
+import org.apache.usergrid.persistence.model.entity.Id;
+
+/**
+ * Classy class class.
+ */
+public class SearchType{
+    private final String type;
+
+    private SearchType( final String type ) {this.type = type;}
+
+    public static SearchType fromType( final String type ) {
+        return new SearchType( type );
+    }
+
+
+    public static SearchType fromId( final Id id ) {
+        return new SearchType( id.getType() );
+    }
+
+
+
+    public String getTypeName(ApplicationScope applicationScope) {
+        final String typeName =  IndexingUtils.getType(applicationScope, type);
+        return typeName;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/947f0632/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
index 977fe51..c0d0d1e 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
@@ -117,8 +117,8 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
         String indexId = createIndexDocId( entity, context );
 
         log.debug( "Indexing entity documentId {} data {} ", indexId, entityAsMap );
-        final String entityType =IndexingUtils.getType(applicationScope, entity.getId());
-        container.addIndexRequest(new IndexRequest(alias.getWriteAlias(), entityType, indexId, entityAsMap));
+        final SearchType entityType =SearchType.fromId(entity.getId());
+        container.addIndexRequest(new IndexRequest(alias.getWriteAlias(), entityType.getTypeName(applicationScope), indexId, entityAsMap));
 
         return this;
     }
@@ -132,7 +132,7 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
         ValidationUtils.verifyVersion( version );
 
         final String context = createContextName(indexScope);
-        final String entityType =IndexingUtils.getType(applicationScope, id);
+        final SearchType entityType =SearchType.fromId(id);
 
         final String indexId = createIndexDocId( id, version, context );
 
@@ -151,14 +151,13 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
                 } );
         }
 
-
         String[] indexes = entityIndex.getIndexes(AliasedEntityIndex.AliasType.Read);
         //get the default index if no alias exists yet
         if(indexes == null ||indexes.length == 0){
             indexes = new String[]{indexIdentifier.getIndex(null)};
         }
 
-        container.addDeIndexRequest( new DeIndexRequest( indexes, entityType, indexId ) );
+        container.addDeIndexRequest( new DeIndexRequest( indexes, entityType.getTypeName(applicationScope), indexId ) );
 
         log.debug("Deindexed Entity with index id " + indexId);
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/947f0632/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 110b320..f8415df 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
@@ -199,9 +199,9 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
         final int numberOfShards = config.getNumberOfShards();
         final int numberOfReplicas = config.getNumberOfReplicas();
         String[] indexes = getIndexesFromEs(AliasType.Write);
-//        if(indexes == null || indexes.length==0) {
+        if(indexes == null || indexes.length==0) {
             addIndex(null, numberOfShards, numberOfReplicas, config.getWriteConsistencyLevel());
-//        }
+        }
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/947f0632/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
index 22ca51f..047fbe8 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
@@ -576,7 +576,7 @@ public class EntityIndexTest extends BaseIT {
         EntityIndex ei = eif.createEntityIndex( applicationScope );
 
         assertNotEquals( "cluster should be ok", Health.RED, ei.getClusterHealth() );
-        assertEquals( "index not be ready yet", Health.RED, ei.getIndexHealth() );
+        assertEquals( "index should be ready", Health.GREEN, ei.getIndexHealth() );
 
         ei.initializeIndex();
         ei.refresh();


[5/5] incubator-usergrid git commit: Merge branch 'two-dot-o' into USERGRID-480

Posted by sf...@apache.org.
Merge branch 'two-dot-o' into USERGRID-480


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/89f2c2f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/89f2c2f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/89f2c2f1

Branch: refs/heads/USERGRID-480
Commit: 89f2c2f1f5b9cc864bfe047a6813dd15dae01483
Parents: 947f063 eb0c689
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Mar 18 15:54:17 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Mar 18 15:54:17 2015 -0600

----------------------------------------------------------------------
 .../index/impl/EsEntityIndexImpl.java           | 83 +++++++++-----------
 1 file changed, 35 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/89f2c2f1/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------