usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [1/2] incubator-usergrid git commit: WIP Overwrite
Date Fri, 07 Nov 2014 00:42:32 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/es-type-updates 10fbde020 -> 707747d1e


WIP Overwrite


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

Branch: refs/heads/es-type-updates
Commit: 3cd6040bff9601239f29425ef40fb43d18f7ab0c
Parents: 10fbde0
Author: Todd Nine <tnine@apigee.com>
Authored: Thu Nov 6 16:55:13 2014 -0700
Committer: Todd Nine <tnine@apigee.com>
Committed: Thu Nov 6 16:55:13 2014 -0700

----------------------------------------------------------------------
 .../index/impl/EsEntityIndexBatchImpl.java      |   2 +-
 .../index/impl/EsEntityIndexImpl.java           | 136 +++++++++++--------
 .../persistence/index/impl/IndexingUtils.java   |  62 +++++----
 .../impl/EntityConnectionIndexImplTest.java     |  45 +++---
 .../persistence/index/impl/EsRunner.java        |   2 +-
 5 files changed, 137 insertions(+), 110 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3cd6040b/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 5a19d1e..a70a8d8 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
@@ -116,7 +116,7 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
 
         if ( log.isDebugEnabled() ) {
             log.debug( "Indexing entity {}:{} in scope\n   app {}\n   "
-                    + "owner {}\n   name {}\n   type {} \n scope type{}", new Object[] {
+                    + "owner {}\n   name {}\n   type {} \n scope type {}", new Object[] {
                     entity.getId().getType(), entity.getId().getUuid(), applicationScope.getApplication(),
                     indexScope.getOwner(), indexScope.getName(), entityType, context
             } );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3cd6040b/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 7378ecd..6d8810c 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
@@ -33,17 +33,14 @@ import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.action.search.SearchScrollRequestBuilder;
 import org.elasticsearch.client.AdminClient;
-import org.elasticsearch.client.Client;
 import org.elasticsearch.common.settings.ImmutableSettings;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.common.xcontent.XContentFactory;
 import org.elasticsearch.index.query.FilterBuilder;
-import org.elasticsearch.index.query.FilterBuilders;
 import org.elasticsearch.index.query.MatchAllQueryBuilder;
 import org.elasticsearch.index.query.QueryBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
-import org.elasticsearch.index.query.TermFilterBuilder;
 import org.elasticsearch.indices.IndexAlreadyExistsException;
 import org.elasticsearch.indices.IndexMissingException;
 import org.elasticsearch.search.SearchHit;
@@ -54,8 +51,6 @@ import org.elasticsearch.search.sort.SortOrder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.apache.lucene.queryparser.xml.FilterBuilderFactory;
-
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.core.util.Health;
 import org.apache.usergrid.persistence.core.util.ValidationUtils;
@@ -148,12 +143,12 @@ public class EsEntityIndexImpl implements EntityIndex {
             final int numberOfShards = config.getNumberOfShards();
             final int numberOfReplicas = config.getNumberOfReplicas();
 
-            Settings settings = ImmutableSettings.settingsBuilder()
-            .put("index.number_of_shards", numberOfShards )
-            .put("index.number_of_replicas", numberOfReplicas).build();
+            Settings settings = ImmutableSettings.settingsBuilder().put( "index.number_of_shards",
numberOfShards )
+                                                 .put( "index.number_of_replicas", numberOfReplicas
).build();
 
 
-            final  CreateIndexResponse cir = admin.indices().prepareCreate( indexName ).setSettings(
settings ).execute().actionGet();
+            final CreateIndexResponse cir =
+                    admin.indices().prepareCreate( indexName ).setSettings( settings ).execute().actionGet();
 
             logger.info( "Created new Index Name [{}] ACK=[{}]", indexName, cir.isAcknowledged()
);
 
@@ -175,8 +170,8 @@ public class EsEntityIndexImpl implements EntityIndex {
 
 
     /**
-     * Tests writing a document to a new index to ensure it's working correctly. 
-     * See this post: http://s.apache.org/index-missing-exception
+     * Tests writing a document to a new index to ensure it's working correctly. See this
post:
+     * http://s.apache.org/index-missing-exception
      */
     private void testNewIndex() {
 
@@ -188,18 +183,17 @@ public class EsEntityIndexImpl implements EntityIndex {
             public boolean doOp() {
                 final String tempId = UUIDGenerator.newTimeUUID().toString();
 
-                esProvider.getClient().prepareIndex( indexName, VERIFY_TYPE, tempId )
-                        .setSource( DEFAULT_PAYLOAD ).get();
+                esProvider.getClient().prepareIndex( indexName, VERIFY_TYPE, tempId ).setSource(
DEFAULT_PAYLOAD )
+                          .get();
 
-                logger.info( "Successfully created new document with docId {} in index {}
and type {}", 
-                        tempId, indexName, VERIFY_TYPE );
+                logger.info( "Successfully created new document with docId {} in index {}
and type {}", tempId,
+                        indexName, VERIFY_TYPE );
 
                 // delete all types, this way if we miss one it will get cleaned up
                 esProvider.getClient().prepareDeleteByQuery( indexName ).setTypes( VERIFY_TYPE
)
-                        .setQuery( MATCH_ALL_QUERY_BUILDER ).get();
+                          .setQuery( MATCH_ALL_QUERY_BUILDER ).get();
 
-                logger.info( "Successfully deleted all documents in index {} and type {}",

-                        indexName, VERIFY_TYPE );
+                logger.info( "Successfully deleted all documents in index {} and type {}",
indexName, VERIFY_TYPE );
 
                 return true;
             }
@@ -218,10 +212,11 @@ public class EsEntityIndexImpl implements EntityIndex {
         XContentBuilder xcb =
                 IndexingUtils.createDoubleStringIndexMapping( XContentFactory.jsonBuilder(),
"_default_" );
 
-        PutIndexTemplateResponse pitr = esProvider.getClient().admin().indices().preparePutTemplate(
"usergrid_template" )
-                                              .setTemplate( config.getIndexPrefix() + "*"
).addMapping( "_default_",
+        PutIndexTemplateResponse pitr =
+                esProvider.getClient().admin().indices().preparePutTemplate( "usergrid_template"
)
+                          .setTemplate( config.getIndexPrefix() + "*" ).addMapping( "_default_",
                         xcb ) // set mapping as the default for all types
-                .execute().actionGet();
+                        .execute().actionGet();
     }
 
 
@@ -239,38 +234,58 @@ public class EsEntityIndexImpl implements EntityIndex {
 
         QueryBuilder qb = query.createQueryBuilder();
 
-        if ( logger.isDebugEnabled() ) {
-            logger.debug( "Searching index {}\n  scope{} \n type {}\n   query {} limit {}",
new Object[] {
-                    this.indexName, context, entityTypes, qb.toString().replace( "\n", "
" ), query.getLimit()
-            } );
-        }
 
         SearchResponse searchResponse;
 
         if ( query.getCursor() == null ) {
-            SearchRequestBuilder srb =
-                    esProvider.getClient().prepareSearch( indexName ).setTypes( entityTypes
).setScroll(
-                            cursorTimeout + "m" )
-                          .setQuery( qb );
+            SearchRequestBuilder srb = esProvider.getClient().prepareSearch( indexName ).setTypes(
entityTypes )
+                                                 .setScroll( cursorTimeout + "m" );
 
-            final TermFilterBuilder contextFilter = FilterBuilders.termFilter( IndexingUtils.ENTITY_CONTEXT,
context );
 
-            final FilterBuilder fb = query.createFilterBuilder();
+            //we must add a "must" operation to our entity context.
+
+            /**
+             * Add our filter for context to our query for fast execution.  Fast because
it utilizes bitsets
+             * internally. See this post for more detail.
+             * http://www.elasticsearch.org/blog/all-about-elasticsearch-filter-bitsets/
+             *
+             *
+             * TODO evaluate performance when it's an all query.  Do we need to put the context
term first for
+             * performance?
+             */
+
+
+            final QueryBuilder finalQuery;
+
+            if ( qb instanceof MatchAllQueryBuilder ) {
+                finalQuery = QueryBuilders.termQuery( IndexingUtils.ENTITY_CONTEXT, context
);
+            }
+            else {
+                finalQuery = QueryBuilders.boolQuery().must( qb )
+                                          .must( QueryBuilders.termQuery( IndexingUtils.ENTITY_CONTEXT,
context ) );
+            }
+
+            //set our final query
+            srb.setQuery( finalQuery );
+
+            if ( logger.isDebugEnabled() ) {
+                        logger.debug( "Searching index {}\n  scope{} \n type {}\n   query
{} limit {}", new Object[] {
+                                this.indexName, context, entityTypes, finalQuery.toString().replace(
"\n", " " ), query.getLimit()
+                        } );
+                    }
 
 
 
+            final FilterBuilder fb = query.createFilterBuilder();
+
+
             //we have post filters, apply them
             if ( fb != null ) {
-//                final FilterBuilder postFilters = FilterBuilders.andFilter(fb, contextFilter
 );
-
                 logger.debug( "   Filter: {} ", fb.toString() );
-//                srb = srb.setPostFilter( postFilters );
-            }
-            //no other post filters, just the types
-            else{
-//                srb.setPostFilter( contextFilter );
+                srb = srb.setPostFilter( fb );
             }
 
+
             srb = srb.setFrom( 0 ).setSize( query.getLimit() );
 
             for ( Query.SortPredicate sp : query.getSortPredicates() ) {
@@ -289,20 +304,20 @@ public class EsEntityIndexImpl implements EntityIndex {
                 // to ignore any fields that are not present.
 
                 final String stringFieldName = STRING_PREFIX + sp.getPropertyName();
-                final FieldSortBuilder stringSort = SortBuilders.fieldSort( stringFieldName
)
-                        .order( order ).ignoreUnmapped( true );
+                final FieldSortBuilder stringSort =
+                        SortBuilders.fieldSort( stringFieldName ).order( order ).ignoreUnmapped(
true );
                 srb.addSort( stringSort );
                 logger.debug( "   Sort: {} order by {}", stringFieldName, order.toString()
);
 
                 final String numberFieldName = NUMBER_PREFIX + sp.getPropertyName();
-                final FieldSortBuilder numberSort = SortBuilders.fieldSort( numberFieldName
)
-                        .order( order ).ignoreUnmapped( true );
+                final FieldSortBuilder numberSort =
+                        SortBuilders.fieldSort( numberFieldName ).order( order ).ignoreUnmapped(
true );
                 srb.addSort( numberSort );
                 logger.debug( "   Sort: {} order by {}", numberFieldName, order.toString()
);
 
                 final String booleanFieldName = BOOLEAN_PREFIX + sp.getPropertyName();
-                final FieldSortBuilder booleanSort = SortBuilders.fieldSort( booleanFieldName
)
-                        .order( order ).ignoreUnmapped( true );
+                final FieldSortBuilder booleanSort =
+                        SortBuilders.fieldSort( booleanFieldName ).order( order ).ignoreUnmapped(
true );
                 srb.addSort( booleanSort );
                 logger.debug( "   Sort: {} order by {}", booleanFieldName, order.toString()
);
             }
@@ -329,7 +344,8 @@ public class EsEntityIndexImpl implements EntityIndex {
             }
             logger.debug( "Executing query with cursor: {} ", scrollId );
 
-            SearchScrollRequestBuilder ssrb = esProvider.getClient().prepareSearchScroll(
scrollId ).setScroll( cursorTimeout + "m" );
+            SearchScrollRequestBuilder ssrb =
+                    esProvider.getClient().prepareSearchScroll( scrollId ).setScroll( cursorTimeout
+ "m" );
 
             try {
                 searchResponse = ssrb.execute().actionGet();
@@ -386,7 +402,7 @@ public class EsEntityIndexImpl implements EntityIndex {
                     return true;
                 }
                 catch ( IndexMissingException e ) {
-                    logger.error( "Unable to refresh index after create. Waiting before sleeping.",
e);
+                    logger.error( "Unable to refresh index after create. Waiting before sleeping.",
e );
                     throw e;
                 }
             }
@@ -424,7 +440,6 @@ public class EsEntityIndexImpl implements EntityIndex {
 
     /**
      * Do the retry operation
-     * @param operation
      */
     private void doInRetry( final RetryOperation operation ) {
         for ( int i = 0; i < MAX_WAITS; i++ ) {
@@ -456,13 +471,13 @@ public class EsEntityIndexImpl implements EntityIndex {
     public Health getClusterHealth() {
 
         try {
-            ClusterHealthResponse chr = esProvider.getClient().admin().cluster()
-                .health( new ClusterHealthRequest() ).get();
+            ClusterHealthResponse chr =
+                    esProvider.getClient().admin().cluster().health( new ClusterHealthRequest()
).get();
             return Health.valueOf( chr.getStatus().name() );
-        } 
-        catch (Exception ex) {
-            logger.error("Error connecting to ElasticSearch", ex);
-        } 
+        }
+        catch ( Exception ex ) {
+            logger.error( "Error connecting to ElasticSearch", ex );
+        }
 
         // this is bad, red alert!
         return Health.RED;
@@ -474,15 +489,16 @@ public class EsEntityIndexImpl implements EntityIndex {
      */
     @Override
     public Health getIndexHealth() {
-        
+
         try {
             ClusterHealthResponse chr = esProvider.getClient().admin().cluster()
-                .health( new ClusterHealthRequest( new String[] { indexName } ) ).get();
+                                                  .health( new ClusterHealthRequest( new
String[] { indexName } ) )
+                                                  .get();
             return Health.valueOf( chr.getStatus().name() );
-        } 
-        catch (Exception ex) {
-            logger.error("Error connecting to ElasticSearch", ex);
-        } 
+        }
+        catch ( Exception ex ) {
+            logger.error( "Error connecting to ElasticSearch", ex );
+        }
 
         // this is bad, red alert!
         return Health.RED;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3cd6040b/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 c8e0b86..cb82f6f 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
@@ -37,17 +37,23 @@ public class IndexingUtils {
     public static final String NUMBER_PREFIX = "nu_";
     public static final String BOOLEAN_PREFIX = "bu_";
 
-    public static final String ENTITYID_FIELDNAME = "entityId";
 
-    public static final String DOC_ID_SEPARATOR = "|";
-    public static final String DOC_ID_SEPARATOR_SPLITTER = "\\|";
+
+    public static final String DOC_ID_SEPARATOR = "__";
+    public static final String DOC_ID_SEPARATOR_SPLITTER = "\\__";
 
     // These are not allowed in document type names: _ . , | #
-    public static final String DOC_TYPE_SEPARATOR = "^";
+    public static final String DOC_TYPE_SEPARATOR = "__";
+
+    public static final String INDEX_NAME_SEPARATOR = "__";
+
+    /**
+     * Reserved UG fields.
+     */
 
-    public static final String INDEX_NAME_SEPARATOR = "^";
+    public static final String ENTITY_CONTEXT = "ug_context";
 
-    public static final String ENTITY_CONTEXT = "_context";
+    public static final String ENTITYID_FIELDNAME = "ug_entityId";
 
     /**
      * To be used when we want to search all types within a scope
@@ -92,8 +98,8 @@ public class IndexingUtils {
      * @param entity
      * @return
      */
-    public static String createIndexDocId(final Entity entity, final String scopeType) {
-        return createIndexDocId(entity.getId(), entity.getVersion(), scopeType);
+    public static String createIndexDocId(final Entity entity, final String context) {
+        return createIndexDocId(entity.getId(), entity.getVersion(), context);
     }
 
 
@@ -101,14 +107,15 @@ public class IndexingUtils {
      * Create the doc Id. This is the entitie's type + uuid + version
      * @param entityId
      * @param version
+     * @para context The context it's indexed in
      * @return
      */
-    public static String createIndexDocId(final Id entityId, final UUID version, final String
scopeType) {
+    public static String createIndexDocId(final Id entityId, final UUID version, final String
context) {
         StringBuilder sb = new StringBuilder();
         sb.append( entityId.getUuid() ).append(DOC_ID_SEPARATOR);
         sb.append( entityId.getType() ).append(DOC_ID_SEPARATOR);
         sb.append( version.toString() ).append( DOC_ID_SEPARATOR );
-        sb.append( scopeType);
+        sb.append( context);
         return sb.toString();
     }
 
@@ -135,25 +142,31 @@ public class IndexingUtils {
 
                     .startArray( "dynamic_templates" )
 
+                           //we need most specific mappings first since it's a stop on match
algorithm
+                        .startObject( "context_template" )
+                            .field( "match", IndexingUtils.ENTITY_CONTEXT )
+                            .field( "match_mapping_type", "string" )
+                                .startObject( "mapping" ).field( "type", "string" )
+                                    .field( "index", "not_analyzed" ).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( "template_1" ).field( "match", ANALYZED_STRING_PREFIX
+ "*" )
+                            .field( "match_mapping_type", "string" )
                                 .startObject( "mapping" ).field( "type", "string" )
                                     .field( "index", "analyzed" )
                                 .endObject()
                             .endObject()
                         .endObject()
 
-                            // all other strings are not analyzed
+                                // all other strings are not analyzed
                         .startObject()
                             .startObject( "template_2" )
-                //todo, should be string prefix, remove 2 field mapping
-                                .field( "match", "*" )
-                                .field( "match_mapping_type", "string" )
-                                .startObject( "mapping" )
-                                    .field( "type", "string" )
+                                    //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" )
                                 .endObject()
                             .endObject()
@@ -169,16 +182,7 @@ public class IndexingUtils {
                             .endObject()
                         .endObject()
 
-                //types for context direct string matching
-                .startObject( "context_template" )
-                        .field( "match", IndexingUtils.ENTITY_CONTEXT )
-                        .field( "match_mapping_type", "string" )
-                        .startObject( "mapping" )
-                            .field( "type", "string" )
-                            .field( "index", "not_analyzed" )
-                        .endObject()
-                    .endObject()
-                .endObject()
+
 
                     .endArray()
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3cd6040b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java
b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java
index c1c075e..d2423bb 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java
@@ -40,6 +40,7 @@ import org.apache.usergrid.persistence.index.EntityIndexFactory;
 import org.apache.usergrid.persistence.index.IndexScope;
 import org.apache.usergrid.persistence.index.SearchTypes;
 import org.apache.usergrid.persistence.index.guice.TestIndexModule;
+import org.apache.usergrid.persistence.index.query.CandidateResult;
 import org.apache.usergrid.persistence.index.query.CandidateResults;
 import org.apache.usergrid.persistence.index.query.Query;
 import org.apache.usergrid.persistence.model.entity.Entity;
@@ -51,6 +52,7 @@ import com.google.inject.Inject;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
 
 
 @RunWith( EsRunner.class )
@@ -59,15 +61,9 @@ public class EntityConnectionIndexImplTest extends BaseIT {
 
     private static final Logger log = LoggerFactory.getLogger( EntityConnectionIndexImplTest.class
);
 
-    @ClassRule
-    public static ElasticSearchResource es = new ElasticSearchResource();
+//    @ClassRule
+//    public static ElasticSearchResource es = new ElasticSearchResource();
 
-    @ClassRule
-    public static CassandraRule cass = new CassandraRule();
-
-    @Inject
-    @Rule
-    public MigrationManagerRule migrationManagerRule;
 
     @Inject
     public EntityIndexFactory ecif;
@@ -121,7 +117,7 @@ public class EntityConnectionIndexImplTest extends BaseIT {
         IndexScope searchScope = new IndexScopeImpl( personId, "likes" );
 
         //create another scope we index in, want to be sure these scopes are filtered
-        IndexScope otherIndexScope = new IndexScopeImpl( new SimpleId( UUIDGenerator.newTimeUUID(),
"person" ), "likes" );
+        IndexScope otherIndexScope = new IndexScopeImpl( new SimpleId( UUIDGenerator.newTimeUUID(),
"animal" ), "likes" );
 
         EntityIndex personLikesIndex = ecif.createEntityIndex( applicationScope );
 
@@ -142,6 +138,7 @@ public class EntityConnectionIndexImplTest extends BaseIT {
         batch.index( otherIndexScope, oj );
 
         batch.executeAndRefresh();
+        personLikesIndex.refresh();
 
         // now, let's search for muffins
         CandidateResults likes = personLikesIndex
@@ -167,18 +164,18 @@ public class EntityConnectionIndexImplTest extends BaseIT {
                 SearchTypes.fromTypes( muffin.getId().getType(), egg.getId().getType(), oj.getId().getType()
),
                 Query.fromQL( "select *" ) );
         assertEquals( 3, likes.size() );
-        assertEquals( muffin.getId(), likes.get( 0 ).getId() );
-        assertEquals( egg.getId(), likes.get( 1 ).getId() );
-        assertEquals( oj.getId(), likes.get( 2 ).getId() );
+        assertContains( egg.getId(), likes );
+        assertContains( muffin.getId(), likes );
+        assertContains( oj.getId(), likes );
 
           //now lets search for all explicitly
         likes = personLikesIndex.search( searchScope,
                 SearchTypes.allTypes(),
                 Query.fromQL( "select *" ) );
         assertEquals( 3, likes.size() );
-        assertEquals( muffin.getId(), likes.get( 0 ).getId() );
-        assertEquals( egg.getId(), likes.get( 1 ).getId() );
-        assertEquals( oj.getId(), likes.get( 2 ).getId() );
+        assertContains( egg.getId(), likes );
+        assertContains( muffin.getId(), likes);
+        assertContains( oj.getId(), likes );
 
 
 
@@ -187,16 +184,26 @@ public class EntityConnectionIndexImplTest extends BaseIT {
                 SearchTypes.fromTypes( muffin.getId().getType(), egg.getId().getType(), oj.getId().getType()
),
                 Query.fromQL( "select * where stars = 5" ) );
         assertEquals( 2, likes.size() );
-        assertEquals( muffin.getId(), likes.get( 0 ).getId() );
-        assertEquals( egg.getId(), likes.get( 1 ).getId() );
+        assertContains( egg.getId(), likes);
+        assertContains( muffin.getId(), likes );
 
 
 
         //now search with no types, we should get only the results that match
         likes = personLikesIndex.search( searchScope, SearchTypes.allTypes(), Query.fromQL(
"select * where stars = 5" ) );
         assertEquals( 2, likes.size() );
-        assertEquals( muffin.getId(), likes.get( 0 ).getId() );
-        assertEquals( egg.getId(), likes.get( 1 ).getId() );
+        assertContains( egg.getId(), likes);
+        assertContains( muffin.getId(), likes );
+    }
+
+
+    private void assertContains(final Id id, final CandidateResults results ){
+        for( CandidateResult result: results){
+            if(result.getId().equals(id)){
+                return;
+            }
+        }
 
+        fail(String.format("Could not find id %s in candidate results", id));
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3cd6040b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EsRunner.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EsRunner.java
b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EsRunner.java
index c972851..2521a38 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EsRunner.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EsRunner.java
@@ -36,7 +36,7 @@ public class EsRunner extends ITRunner {
         ElasticSearchResource rule = new ElasticSearchResource();
 
         try {
-            rule.before();
+//            rule.before();
         }
         catch ( Throwable throwable ) {
             throw new RuntimeException( "Unable to start ES", throwable );


Mime
View raw message