usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [04/33] incubator-usergrid git commit: Moved files to reflect their public/internal usage
Date Mon, 13 Apr 2015 19:18:11 GMT
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/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 8de4832..7a43f98 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,7 +50,6 @@ import org.elasticsearch.index.query.MatchAllQueryBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.indices.IndexAlreadyExistsException;
 import org.elasticsearch.indices.IndexMissingException;
-import org.elasticsearch.indices.InvalidAliasNameException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -93,7 +92,7 @@ public class EsEntityIndexImpl implements AliasedEntityIndex,VersionedData {
             ImmutableMap.<String, Object>builder().put( "field", "test" ).put(IndexingUtils.ENTITYID_ID_FIELDNAME, UUIDGenerator.newTimeUUID().toString()).build();
 
     private static final MatchAllQueryBuilder MATCH_ALL_QUERY_BUILDER = QueryBuilders.matchAllQuery();
-    private final IndexIdentifier indexIdentifier;
+    private final FailureMonitorImpl.IndexIdentifier indexIdentifier;
 
     private IndexCache aliasCache;
     private Timer mappingTimer;
@@ -107,7 +106,7 @@ public class EsEntityIndexImpl implements AliasedEntityIndex,VersionedData {
     public EsEntityIndexImpl(
                               final IndexBufferProducer indexBatchBufferProducer, final EsProvider provider,
                               final IndexCache indexCache, final MetricsFactory metricsFactory,
-                              final IndexFig indexFig, final IndexIdentifier indexIdentifier ) {
+                              final IndexFig indexFig, final FailureMonitorImpl.IndexIdentifier indexIdentifier ) {
         this.indexBatchBufferProducer = indexBatchBufferProducer;
         this.indexFig = indexFig;
         this.indexIdentifier = indexIdentifier;
@@ -320,7 +319,7 @@ public class EsEntityIndexImpl implements AliasedEntityIndex,VersionedData {
 
         refreshIndexMeter.mark();
         final Timer.Context timeRefreshIndex = refreshTimer.time();
-        BetterFuture future = indexBatchBufferProducer.put(new IndexOperationMessage());
+        BetterFuture future = indexBatchBufferProducer.put(new IndexIdentifierImpl.IndexOperationMessage());
         future.get();
         //loop through all batches and retrieve promises and call get
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
index 0377f40..558f796 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
@@ -34,9 +34,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
-import org.apache.usergrid.persistence.index.IndexBufferConsumer;
 import org.apache.usergrid.persistence.index.IndexFig;
-import org.apache.usergrid.persistence.index.IndexOperationMessage;
 
 import com.codahale.metrics.Counter;
 import com.codahale.metrics.Gauge;
@@ -48,7 +46,6 @@ import com.google.inject.Singleton;
 import rx.Observable;
 import rx.Subscriber;
 import rx.Subscription;
-import rx.functions.Action1;
 import rx.schedulers.Schedulers;
 
 
@@ -142,16 +139,16 @@ public class EsIndexBufferConsumerImpl implements IndexBufferConsumer {
     private void startWorker(){
         synchronized ( mutex) {
 
-            Observable<List<IndexOperationMessage>> consumer = Observable.create(
-                new Observable.OnSubscribe<List<IndexOperationMessage>>() {
+            Observable<List<IndexIdentifierImpl.IndexOperationMessage>> consumer = Observable.create(
+                new Observable.OnSubscribe<List<IndexIdentifierImpl.IndexOperationMessage>>() {
                     @Override
-                    public void call( final Subscriber<? super List<IndexOperationMessage>> subscriber ) {
+                    public void call( final Subscriber<? super List<IndexIdentifierImpl.IndexOperationMessage>> subscriber ) {
 
                         //name our thread so it's easy to see
                         Thread.currentThread().setName( "QueueConsumer_" + counter.incrementAndGet() );
 
 
-                        List<IndexOperationMessage> drainList = null;
+                        List<IndexIdentifierImpl.IndexOperationMessage> drainList = null;
 
                         do {
 
@@ -229,7 +226,7 @@ public class EsIndexBufferConsumerImpl implements IndexBufferConsumer {
     /**
      * Execute the request, check for errors, then re-init the batch for future use
      */
-    private void execute( final List<IndexOperationMessage> operationMessages ) {
+    private void execute( final List<IndexIdentifierImpl.IndexOperationMessage> operationMessages ) {
 
         if ( operationMessages == null || operationMessages.size() == 0 ) {
             return;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferProducerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferProducerImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferProducerImpl.java
index 61d5d25..9ba92d0 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferProducerImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferProducerImpl.java
@@ -26,13 +26,7 @@ import com.google.inject.Inject;
 import com.google.inject.Singleton;
 import org.apache.usergrid.persistence.core.future.BetterFuture;
 import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
-import org.apache.usergrid.persistence.index.IndexBufferProducer;
-import org.apache.usergrid.persistence.index.IndexFig;
-import org.apache.usergrid.persistence.index.IndexOperationMessage;
-import rx.Subscriber;
 
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.BlockingQueue;
 
 /**
  * Producer for index operation messages
@@ -52,7 +46,7 @@ public class EsIndexBufferProducerImpl implements IndexBufferProducer {
         this.timer =  metricsFactory.getTimer(EsIndexBufferProducerImpl.class,"index.buffer.producer.timer");
     }
 
-    public BetterFuture put(IndexOperationMessage message){
+    public BetterFuture put(IndexIdentifierImpl.IndexOperationMessage message){
         Preconditions.checkNotNull(message, "Message cannot be null");
         indexSizeCounter.inc(message.getDeIndexRequests().size());
         indexSizeCounter.inc(message.getIndexRequests().size());

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/FailureMonitorImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/FailureMonitorImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/FailureMonitorImpl.java
index fed9a50..fe31d35 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/FailureMonitorImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/FailureMonitorImpl.java
@@ -98,4 +98,30 @@ public class FailureMonitorImpl implements FailureMonitor {
     public void success() {
         failCounter.set( 0 );
     }
+
+
+    /**
+     * Identifier for where an index is in underlying server
+     */
+    public static interface IndexIdentifier {
+
+        /**
+         * get the alias name
+         * @return
+         */
+        IndexAlias getAlias();
+
+        /**
+         * get index name from suffix
+         * @param suffix
+         * @return
+         */
+        String getIndex( String suffix );
+
+        /**
+         * return unique string
+         * @return
+         */
+        String toString();
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexAlias.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexAlias.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexAlias.java
new file mode 100644
index 0000000..568ea5f
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexAlias.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.
+ */
+package org.apache.usergrid.persistence.index.impl;
+
+
+import org.apache.usergrid.persistence.index.IndexFig;
+
+
+/**
+ * Abstraction for Index alias names
+ */
+public class IndexAlias{
+    private final String readAlias;
+    private final String writeAlias;
+
+    public IndexAlias(IndexFig indexFig,String indexBase) {
+        this.writeAlias = indexBase + "_write_" + indexFig.getAliasPostfix();
+        this.readAlias = indexBase + "_read_" + indexFig.getAliasPostfix();
+    }
+
+    public String getReadAlias() {
+        return readAlias;
+    }
+
+    public String getWriteAlias() {
+        return writeAlias;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexBufferConsumer.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexBufferConsumer.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexBufferConsumer.java
new file mode 100644
index 0000000..b8e733d
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexBufferConsumer.java
@@ -0,0 +1,37 @@
+/*
+ *
+ *  * 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.impl;
+
+/**
+ *  Buffer index requests
+ */
+public interface IndexBufferConsumer {
+
+
+    /**
+     * Start the consumer
+     */
+    void start();
+
+    /**
+     * Stop the consumers
+     */
+    void stop();
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexBufferProducer.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexBufferProducer.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexBufferProducer.java
new file mode 100644
index 0000000..36cb180
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexBufferProducer.java
@@ -0,0 +1,32 @@
+/*
+ *
+ *  * 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.impl;
+
+import org.apache.usergrid.persistence.core.future.BetterFuture;
+
+
+/**
+ * Produce to index buffer consumer
+ */
+public interface IndexBufferProducer {
+
+    BetterFuture put(IndexIdentifierImpl.IndexOperationMessage message);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexCache.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexCache.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexCache.java
new file mode 100644
index 0000000..aafa67e
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexCache.java
@@ -0,0 +1,43 @@
+/*
+ *
+ *  * 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.impl;
+
+
+import org.apache.usergrid.persistence.index.AliasedEntityIndex;
+
+
+/**
+ * Cache for index lookups
+ */
+public interface IndexCache {
+    /**
+     * get index based on alias name
+     * @param alias
+     * @param aliasType
+     * @return
+     */
+    String[] getIndexes(IndexAlias alias, AliasedEntityIndex.AliasType aliasType);
+
+    /**
+     * invalidate cache
+     * @param alias
+     */
+    void invalidate(IndexAlias alias);
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexEdgeImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexEdgeImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexEdgeImpl.java
new file mode 100644
index 0000000..6744a3f
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexEdgeImpl.java
@@ -0,0 +1,49 @@
+/*
+ *
+ *  *
+ *  * Licensed to the Apache Software Foundation (ASF) under one
+ *  * or more contributor license agreements.  See the NOTICE file
+ *  * distributed with this work for additional information
+ *  * regarding copyright ownership.  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.
+ *  *
+ *
+ */
+
+package org.apache.usergrid.persistence.index.impl;
+
+
+import org.apache.usergrid.persistence.index.IndexEdge;
+import org.apache.usergrid.persistence.model.entity.Id;
+
+
+/**
+ * Implementation of the edge to index
+ */
+public class IndexEdgeImpl extends SearchEdgeImpl implements IndexEdge {
+
+    private final long timestamp;
+
+
+    public IndexEdgeImpl( final Id nodeId, final String name, final long timestamp ) {
+        super( nodeId, name );
+        this.timestamp = timestamp;
+    }
+
+
+    @Override
+    public long getTimestamp() {
+        return timestamp;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexIdentifierImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexIdentifierImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexIdentifierImpl.java
index 0139858..c47b2c8 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexIdentifierImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexIdentifierImpl.java
@@ -20,15 +20,22 @@
 
 package org.apache.usergrid.persistence.index.impl;
 
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.Callable;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.google.inject.Inject;
-import org.apache.usergrid.persistence.index.IndexAlias;
+
+import org.apache.usergrid.persistence.core.future.BetterFuture;
 import org.apache.usergrid.persistence.index.IndexFig;
-import org.apache.usergrid.persistence.index.IndexIdentifier;
+
 
 /**
  * Class is used to generate an index name and alias name
  */
-public class IndexIdentifierImpl implements IndexIdentifier {
+public class IndexIdentifierImpl implements FailureMonitorImpl.IndexIdentifier {
     private final IndexFig config;
 
     @Inject
@@ -65,4 +72,112 @@ public class IndexIdentifierImpl implements IndexIdentifier {
         return "index id"+config.getIndexPrefix();
     }
 
+
+    /**
+     * Container for index operations.
+     */
+    public static class IndexOperationMessage implements Serializable {
+        private final Set<IndexRequest> indexRequests;
+        private final Set<DeIndexRequest> deIndexRequests;
+
+
+
+        private final BetterFuture<IndexOperationMessage> containerFuture;
+
+
+        public IndexOperationMessage() {
+            final IndexOperationMessage parent = this;
+            this.indexRequests = new HashSet<>();
+            this.deIndexRequests = new HashSet<>();
+            this.containerFuture = new BetterFuture<>( new Callable<IndexOperationMessage>() {
+                @Override
+                public IndexOperationMessage call() throws Exception {
+                    return parent;
+                }
+            } );
+        }
+
+
+        public void addIndexRequest( final IndexRequest indexRequest ) {
+            indexRequests.add( indexRequest );
+        }
+
+
+        public void addAllIndexRequest( final Set<IndexRequest> indexRequests ) {
+            this.indexRequests.addAll( indexRequests );
+        }
+
+
+        public void addDeIndexRequest( final DeIndexRequest deIndexRequest ) {
+            this.deIndexRequests.add( deIndexRequest );
+        }
+
+
+        public void addAllDeIndexRequest( final Set<DeIndexRequest> deIndexRequests ) {
+            this.deIndexRequests.addAll( deIndexRequests );
+        }
+
+
+        public Set<IndexRequest> getIndexRequests() {
+            return indexRequests;
+        }
+
+
+        public Set<DeIndexRequest> getDeIndexRequests() {
+            return deIndexRequests;
+        }
+
+
+        @JsonIgnore
+        public boolean isEmpty(){
+            return indexRequests.isEmpty() && deIndexRequests.isEmpty();
+        }
+
+        /**
+         * return the promise
+         */
+        @JsonIgnore
+        public BetterFuture<IndexOperationMessage> getFuture() {
+            return containerFuture;
+        }
+
+
+        @Override
+        public boolean equals( final Object o ) {
+            if ( this == o ) {
+                return true;
+            }
+            if ( o == null || getClass() != o.getClass() ) {
+                return false;
+            }
+
+            final IndexOperationMessage that = ( IndexOperationMessage ) o;
+
+            if ( !deIndexRequests.equals( that.deIndexRequests ) ) {
+                return false;
+            }
+            if ( !indexRequests.equals( that.indexRequests ) ) {
+                return false;
+            }
+
+            return true;
+        }
+
+
+        @Override
+        public int hashCode() {
+            int result = indexRequests.hashCode();
+            result = 31 * result + deIndexRequests.hashCode();
+            return result;
+        }
+
+        public void done() {
+            //if this has been serialized, it could be null. don't NPE if it is, there's nothing to ack
+            final BetterFuture<IndexOperationMessage> future = getFuture();
+
+            if(future != null ){
+                future.done();
+            }
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexRequest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexRequest.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexRequest.java
index dc05820..bf2409a 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexRequest.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexRequest.java
@@ -23,17 +23,16 @@ package org.apache.usergrid.persistence.index.impl;
 import java.util.Map;
 
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
-import org.apache.usergrid.persistence.index.IndexScope;
+import org.apache.usergrid.persistence.index.SearchEdge;
 import org.apache.usergrid.persistence.index.SearchType;
 import org.apache.usergrid.persistence.model.entity.Entity;
-import org.apache.usergrid.persistence.model.entity.Id;
+
 import org.elasticsearch.action.bulk.BulkRequestBuilder;
 import org.elasticsearch.action.index.IndexRequestBuilder;
 import org.elasticsearch.client.Client;
 
 import com.fasterxml.jackson.annotation.JsonTypeInfo;
 
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.APPLICATION_ID_FIELDNAME;
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.createContextName;
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.idString;
 
@@ -50,8 +49,8 @@ public class IndexRequest implements BatchRequest {
 
     public Map<String, Object> data;
 
-    public IndexRequest( final String writeAlias, final ApplicationScope applicationScope, IndexScope indexScope, Entity entity) {
-        this(writeAlias, applicationScope, createContextName(applicationScope, indexScope), entity);
+    public IndexRequest( final String writeAlias, final ApplicationScope applicationScope, SearchEdge searchEdge, Entity entity) {
+        this(writeAlias, applicationScope, createContextName(applicationScope, searchEdge ), entity);
     }
 
     public IndexRequest( final String writeAlias, final ApplicationScope applicationScope, String context , Entity entity) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexScopeImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexScopeImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexScopeImpl.java
deleted file mode 100644
index 13002e3..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexScopeImpl.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  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.
- */
-package org.apache.usergrid.persistence.index.impl;
-
-import org.apache.usergrid.persistence.index.IndexScope;
-import org.apache.usergrid.persistence.index.utils.IndexValidationUtils;
-import org.apache.usergrid.persistence.model.entity.Id;
-
-
-public class IndexScopeImpl implements IndexScope {
-    private final Id ownerId;
-    private final String name;
-
-
-    public IndexScopeImpl( final Id ownerId, final String name ) {
-        this.ownerId = ownerId;
-        this.name = name;
-
-        IndexValidationUtils.validateIndexScope( this );
-    }
-
-
-    @Override
-    public String getName() {
-        return  name;
-    }
-
-
-    @Override
-    public Id getOwner() {
-        return ownerId;
-    }
-
-
-    @Override
-    public boolean equals( final Object o ) {
-        if ( this == o ) {
-            return true;
-        }
-        if ( !( o instanceof IndexScopeImpl ) ) {
-            return false;
-        }
-
-        final IndexScopeImpl that = ( IndexScopeImpl ) o;
-
-        if ( !ownerId.equals( that.ownerId ) ) {
-            return false;
-        }
-        if ( !name.equals( that.name ) ) {
-            return false;
-        }
-
-        return true;
-    }
-
-
-    @Override
-    public int hashCode() {
-        int result = ownerId.hashCode();
-        result = 31 * result + name.hashCode();
-        return result;
-    }
-
-
-    @Override
-    public String toString() {
-        return "IndexScopeImpl{" +
-                "ownerId=" + ownerId +
-                ", name='" + name + '\'' +
-                '}';
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/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 0330bbf..e066ca2 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
@@ -22,13 +22,13 @@ import java.io.IOException;
 import java.util.UUID;
 
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
-import org.apache.usergrid.persistence.index.IndexFig;
-import org.apache.usergrid.persistence.index.IndexIdentifier;
-import org.apache.usergrid.persistence.index.IndexScope;
+import org.apache.usergrid.persistence.index.SearchEdge;
 import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 
+import org.apache.commons.lang.NotImplementedException;
+
 
 public class IndexingUtils {
 
@@ -67,22 +67,16 @@ public class IndexingUtils {
       * @param scope
       * @return
       */
-     public static String createContextName(ApplicationScope applicationScope, IndexScope scope ) {
+     public static String createContextName(final ApplicationScope applicationScope, final SearchEdge scope ) {
          StringBuilder sb = new StringBuilder();
          idString(sb,applicationScope.getApplication());
          sb.append(SEPARATOR);
-         idString(sb, scope.getOwner());
+         idString(sb, scope.getNodeId());
          sb.append( SEPARATOR );
-         sb.append( scope.getName() );
+         sb.append( scope.getEdgeName() );
          return sb.toString();
      }
-    public static String createLegacyContextName(ApplicationScope applicationScope, IndexScope scope ) {
-        StringBuilder sb = new StringBuilder();
-        idString(sb, scope.getOwner());
-        sb.append( SEPARATOR );
-        sb.append( scope.getName() );
-        return sb.toString();
-    }
+
 
     /**
      * Append the id to the string
@@ -123,13 +117,15 @@ public class IndexingUtils {
      * @para context The context it's indexed in
      * @return
      */
-    public static String createIndexDocId(final Id entityId, final UUID version, final String context) {
-        StringBuilder sb = new StringBuilder();
-        idString(sb, entityId);
-        sb.append( SEPARATOR );
-        sb.append( version.toString() ).append( SEPARATOR );
-        sb.append( context);
-        return sb.toString();
+    public static String createIndexDocId( final Id entityId, final UUID version, final String context) {
+
+        throw new NotImplementedException("Fix me to use app scope too");
+//        StringBuilder sb = new StringBuilder();
+//        idString(sb, entityId);
+//        sb.append( SEPARATOR );
+//        sb.append( version.toString() ).append( SEPARATOR );
+//        sb.append( context);
+//        return sb.toString();
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/SearchEdgeImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/SearchEdgeImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/SearchEdgeImpl.java
new file mode 100644
index 0000000..4a5c376
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/SearchEdgeImpl.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  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.
+ */
+package org.apache.usergrid.persistence.index.impl;
+
+import org.apache.usergrid.persistence.index.SearchEdge;
+import org.apache.usergrid.persistence.index.utils.IndexValidationUtils;
+import org.apache.usergrid.persistence.model.entity.Id;
+
+
+/**
+ * The edge to search on.  Can be either a source--> target edge or a target<-- source edge.  The entiies returned
+ * will be on the opposite side of the edge from the specified nodeId
+ */
+public class SearchEdgeImpl implements SearchEdge {
+    private final Id nodeId;
+    private final String name;
+
+
+    public SearchEdgeImpl( final Id nodeId, final String name ) {
+        this.nodeId = nodeId;
+        this.name = name;
+    }
+
+
+    @Override
+    public Id getNodeId() {
+        return nodeId;
+    }
+
+
+    @Override
+    public String getEdgeName() {
+        return name;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/SearchRequestBuilderStrategy.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/SearchRequestBuilderStrategy.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/SearchRequestBuilderStrategy.java
index 8a378b8..8d4d599 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/SearchRequestBuilderStrategy.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/SearchRequestBuilderStrategy.java
@@ -33,8 +33,7 @@ import org.slf4j.LoggerFactory;
 
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.index.EntityIndex;
-import org.apache.usergrid.persistence.index.IndexAlias;
-import org.apache.usergrid.persistence.index.IndexScope;
+import org.apache.usergrid.persistence.index.SearchEdge;
 import org.apache.usergrid.persistence.index.SearchTypes;
 import org.apache.usergrid.persistence.index.exceptions.IndexException;
 import org.apache.usergrid.persistence.index.query.ParsedQuery;
@@ -48,10 +47,9 @@ import static org.apache.usergrid.persistence.index.impl.IndexingUtils.DOUBLE_PR
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.LONG_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.createLegacyContextName;
 
 /**
- * Classy class class.
+ * The strategy for creating a search request from a parsed query
  */
 
 public class SearchRequestBuilderStrategy {
@@ -71,14 +69,14 @@ public class SearchRequestBuilderStrategy {
         this.cursorTimeout = cursorTimeout;
     }
 
-    public SearchRequestBuilder getBuilder(final IndexScope indexScope, final SearchTypes searchTypes, final ParsedQuery query,  final int limit) {
+    public SearchRequestBuilder getBuilder(final SearchEdge searchEdge, final SearchTypes searchTypes, final ParsedQuery query,  final int limit) {
 
         Preconditions.checkArgument(limit <= EntityIndex.MAX_LIMIT, "limit is greater than max "+ EntityIndex.MAX_LIMIT);
 
         SearchRequestBuilder srb = esProvider.getClient().prepareSearch(alias.getReadAlias())
             .setTypes(searchTypes.getTypeNames(applicationScope))
             .setScroll(cursorTimeout + "m")
-            .setQuery(createQueryBuilder( indexScope,query));
+            .setQuery(createQueryBuilder( searchEdge,query));
 
         final FilterBuilder fb = createFilterBuilder(query);
 
@@ -136,8 +134,8 @@ public class SearchRequestBuilderStrategy {
     }
 
 
-    public QueryBuilder createQueryBuilder( IndexScope indexScope, ParsedQuery query) {
-        String[] contexts = new String[]{createContextName(applicationScope, indexScope),createLegacyContextName(applicationScope,indexScope)};
+    public QueryBuilder createQueryBuilder(final  SearchEdge searchEdge, final ParsedQuery query) {
+        String context = createContextName(applicationScope, searchEdge );
 
         QueryBuilder queryBuilder = null;
 
@@ -166,19 +164,13 @@ public class SearchRequestBuilderStrategy {
 
         // TODO evaluate performance when it's an all query.
         // Do we need to put the context term first for performance?
+
+        //make sure we have entity in the context
         BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
-        for(String context : contexts){
-            boolQueryBuilder = boolQueryBuilder.should(QueryBuilders.termQuery( IndexingUtils.ENTITY_CONTEXT_FIELDNAME, context ));
-        }
-        boolQueryBuilder = boolQueryBuilder.minimumNumberShouldMatch( 1 );
-        if ( queryBuilder != null ) {
-            queryBuilder =  boolQueryBuilder.must( queryBuilder );
-        }
 
-        //nothing was specified ensure we specify the context in the search
-        else {
-            queryBuilder = boolQueryBuilder;
-        }
+        boolQueryBuilder.must(  QueryBuilders.termQuery( IndexingUtils.ENTITY_CONTEXT_FIELDNAME, context ) );
+
+        boolQueryBuilder.must( queryBuilder );
 
         return queryBuilder;
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/EsIndexDataMigrationImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/EsIndexDataMigrationImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/EsIndexDataMigrationImpl.java
index 3706722..458ad01 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/EsIndexDataMigrationImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/EsIndexDataMigrationImpl.java
@@ -24,8 +24,8 @@ import org.apache.usergrid.persistence.core.migration.data.VersionedData;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.index.AliasedEntityIndex;
 import org.apache.usergrid.persistence.index.IndexFig;
-import org.apache.usergrid.persistence.index.IndexIdentifier;
-import org.apache.usergrid.persistence.index.IndexCache;
+import org.apache.usergrid.persistence.index.impl.FailureMonitorImpl;
+import org.apache.usergrid.persistence.index.impl.IndexCache;
 import org.apache.usergrid.persistence.index.impl.EsProvider;
 import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
 import org.elasticsearch.client.AdminClient;
@@ -42,13 +42,13 @@ public class EsIndexDataMigrationImpl implements DataMigration<ApplicationScope>
     private final AliasedEntityIndex entityIndex;
     private final EsProvider provider;
     private final IndexFig indexFig;
-    private final IndexIdentifier indexIdentifier;
+    private final FailureMonitorImpl.IndexIdentifier indexIdentifier;
     private final IndexCache indexCache;
     private final VersionedData dataVersion;
     private static final Logger log = LoggerFactory.getLogger(EsIndexDataMigrationImpl.class);
 
     @Inject
-    public EsIndexDataMigrationImpl(AliasedEntityIndex entityIndex, EsProvider provider, IndexFig indexFig, IndexIdentifier indexIdentifier, IndexCache indexCache){
+    public EsIndexDataMigrationImpl(AliasedEntityIndex entityIndex, EsProvider provider, IndexFig indexFig, FailureMonitorImpl.IndexIdentifier indexIdentifier, IndexCache indexCache){
         this.entityIndex = entityIndex;
         this.provider = provider;
         this.indexFig = indexFig;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/LegacyIndexIdentifier.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/LegacyIndexIdentifier.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/LegacyIndexIdentifier.java
index 5ab3ac1..3efad3b 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/LegacyIndexIdentifier.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/LegacyIndexIdentifier.java
@@ -20,15 +20,15 @@
 package org.apache.usergrid.persistence.index.migration;
 
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
-import org.apache.usergrid.persistence.index.IndexAlias;
+import org.apache.usergrid.persistence.index.impl.FailureMonitorImpl;
+import org.apache.usergrid.persistence.index.impl.IndexAlias;
 import org.apache.usergrid.persistence.index.IndexFig;
-import org.apache.usergrid.persistence.index.IndexIdentifier;
 import org.apache.usergrid.persistence.index.impl.IndexingUtils;
 
 /**
  * Class is used to generate an index name and alias name the old way via app name
  */
-public class LegacyIndexIdentifier implements IndexIdentifier {
+public class LegacyIndexIdentifier implements FailureMonitorImpl.IndexIdentifier {
     private final IndexFig config;
     private final ApplicationScope applicationScope;
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/CandidateResult.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/CandidateResult.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/CandidateResult.java
deleted file mode 100644
index f49cf2d..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/CandidateResult.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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.query;
-
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.core.entity.EntityVersion;
-import org.apache.usergrid.persistence.model.entity.Id;
-
-
-public class CandidateResult implements EntityVersion {
-    private final Id entityId;
-    private final UUID entityVersion;
-
-    public CandidateResult( Id entityId, UUID entityVersion ) {
-        this.entityId = entityId;
-        this.entityVersion = entityVersion;
-    }
-
-    @Override
-    public UUID getVersion() {
-        return entityVersion;
-    }
-
-    @Override
-    public Id getId() {
-        return entityId;
-    }
-
-
-    @Override
-    public boolean equals( final Object o ) {
-        if ( this == o ) {
-            return true;
-        }
-        if ( !( o instanceof CandidateResult ) ) {
-            return false;
-        }
-
-        final CandidateResult that = ( CandidateResult ) o;
-
-        if ( !entityId.equals( that.entityId ) ) {
-            return false;
-        }
-        if ( !entityVersion.equals( that.entityVersion ) ) {
-            return false;
-        }
-
-        return true;
-    }
-
-
-    @Override
-    public int hashCode() {
-        int result = entityId.hashCode();
-        result = 31 * result + entityVersion.hashCode();
-        return result;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/CandidateResults.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/CandidateResults.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/CandidateResults.java
deleted file mode 100644
index 5cb6680..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/CandidateResults.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.query;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * Internal results class, should not be returned as results to a user.
- * Only returns candidate entity results
- */
-public class CandidateResults implements Iterable<CandidateResult> {
-
-    private static final Logger log = LoggerFactory.getLogger(CandidateResults.class);
-
-    private String cursor = null;
-
-
-    private final List<CandidateResult> candidates;
-
-
-    public CandidateResults( List<CandidateResult> candidates ) {
-        this.candidates = candidates;
-    }
-
-    public void add( List<CandidateResult> candidates ) {
-        this.candidates.addAll( candidates);
-    }
-
-    public void initializeCursor(){
-        //USERGRID-461 our cursor is getting too large, map it to a new time UUID
-        //TODO T.N., this shouldn't live here. This should live at the UG core tier.  However the RM/EM are an absolute mess, so until they're refactored, this is it's home
-
-        cursor = org.apache.usergrid.persistence.index.utils.StringUtils.sanitizeUUID(UUIDGenerator.newTimeUUID());
-    }
-
-
-    public boolean hasCursor() {
-        return cursor != null;
-    }
-
-
-    public String getCursor() {
-        return cursor;
-    }
-
-
-    public void setCursor(String cursor) {
-        this.cursor = cursor;
-    }
-
-
-
-
-    public int size() {
-        return candidates.size();
-    }
-
-
-    public boolean isEmpty() {
-        return candidates.isEmpty();
-    }
-
-
-    /**
-     * Get the candidates
-     * @return
-     */
-    public CandidateResult get(int index){
-        return candidates.get( index );
-    }
-
-    @Override
-    public Iterator<CandidateResult> iterator() {
-        return candidates.iterator();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/ParsedQuery.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/ParsedQuery.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/ParsedQuery.java
index a55f8ea..7172447 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/ParsedQuery.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/ParsedQuery.java
@@ -32,6 +32,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.usergrid.persistence.index.SelectFieldMapping;
 import org.apache.usergrid.persistence.index.exceptions.QueryParseException;
 import org.apache.usergrid.persistence.index.query.tree.Operand;
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/SelectFieldMapping.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/SelectFieldMapping.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/SelectFieldMapping.java
deleted file mode 100644
index 88a2780..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/SelectFieldMapping.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- *
- *  *
- *  * Licensed to the Apache Software Foundation (ASF) under one
- *  * or more contributor license agreements.  See the NOTICE file
- *  * distributed with this work for additional information
- *  * regarding copyright ownership.  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.
- *  *
- *
- */
-
-package org.apache.usergrid.persistence.index.query;
-
-
-/**
- * A simple object that represents a field mapping.
- *
- * Examples:
- *  "select id", which will return id
- *
- *  "select id:appfield" which will return id, but rename it appfield
- */
-public class SelectFieldMapping {
-
-    private final String sourceFieldName;
-    private final String targetFieldName;
-
-
-    public SelectFieldMapping( final String sourceFieldName, final String targetFieldName ) {
-        this.sourceFieldName = sourceFieldName;
-        this.targetFieldName = targetFieldName;
-    }
-
-
-    public String getSourceFieldName() {
-        return sourceFieldName;
-    }
-
-
-    public String getTargetFieldName() {
-        return targetFieldName;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/IndexValidationUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/IndexValidationUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/IndexValidationUtils.java
index 7ed546f..bc4b151 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/IndexValidationUtils.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/IndexValidationUtils.java
@@ -19,12 +19,11 @@
 package org.apache.usergrid.persistence.index.utils;
 
 
-import org.apache.usergrid.persistence.core.scope.ApplicationScope;
-import org.apache.usergrid.persistence.index.IndexScope;
+import org.apache.usergrid.persistence.index.IndexEdge;
+import org.apache.usergrid.persistence.index.SearchEdge;
 
 import com.google.common.base.Preconditions;
 
-import static org.apache.usergrid.persistence.core.util.ValidationUtils.validateApplicationScope;
 import static org.apache.usergrid.persistence.core.util.ValidationUtils.verifyIdentity;
 import static org.apache.usergrid.persistence.core.util.ValidationUtils.verifyString;
 
@@ -37,16 +36,25 @@ public class IndexValidationUtils {
 
 
     /**
-     * Validate the collection scope
+     * Validate the search edge is correct
+     * @param searchEdge
      */
-    public static void validateIndexScope( final IndexScope scope ) {
+    public static void validateSearchEdge(final SearchEdge searchEdge){
+        Preconditions.checkNotNull(searchEdge, "searchEdge is required");
+        org.apache.usergrid.persistence.core.util.ValidationUtils.verifyIdentity( searchEdge.getNodeId() );
+        Preconditions.checkArgument( searchEdge.getEdgeName() != null && searchEdge.getEdgeName().length() > 0, "search edge name is required" );
 
-        Preconditions.checkNotNull( scope, "Index scope is required" );
+    }
 
-        verifyIdentity( scope.getOwner() );
 
-        verifyString( scope.getName(), "name" );
 
+    /**
+     * Validate the search edge is correct
+     * @param indexEdge
+     */
+    public static void validateIndexEdge(final IndexEdge indexEdge){
+        //we don't care about timestamp.  It's a primitive so always present
+        validateSearchEdge( indexEdge );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/guice/TestIndexModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/guice/TestIndexModule.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/guice/TestIndexModule.java
index 7b26376..a918003 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/guice/TestIndexModule.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/guice/TestIndexModule.java
@@ -26,10 +26,10 @@ import org.apache.usergrid.persistence.core.migration.data.MigrationDataProvider
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
 import org.apache.usergrid.persistence.index.EntityIndex;
-import org.apache.usergrid.persistence.index.IndexBufferProducer;
+import org.apache.usergrid.persistence.index.impl.IndexBufferProducer;
 import org.apache.usergrid.persistence.index.IndexFig;
 import org.apache.usergrid.persistence.index.impl.EsEntityIndexImpl;
-import org.apache.usergrid.persistence.index.IndexCache;
+import org.apache.usergrid.persistence.index.impl.IndexCache;
 import org.apache.usergrid.persistence.index.impl.EsProvider;
 import org.apache.usergrid.persistence.index.migration.LegacyIndexIdentifier;
 import org.apache.usergrid.persistence.model.entity.SimpleId;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/BufferQueueSQSImplTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/BufferQueueSQSImplTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/BufferQueueSQSImplTest.java
index 6fb6021..f92c57a 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/BufferQueueSQSImplTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/BufferQueueSQSImplTest.java
@@ -25,9 +25,7 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
-import org.apache.usergrid.persistence.index.IndexScope;
 import org.apache.usergrid.persistence.index.SearchType;
-import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
 import org.junit.Before;
 import org.junit.Rule;
@@ -38,7 +36,6 @@ import org.apache.usergrid.persistence.core.guice.MigrationManagerRule;
 import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
 import org.apache.usergrid.persistence.core.test.UseModules;
 import org.apache.usergrid.persistence.index.IndexFig;
-import org.apache.usergrid.persistence.index.IndexOperationMessage;
 import org.apache.usergrid.persistence.index.guice.TestIndexModule;
 import org.apache.usergrid.persistence.map.MapManagerFactory;
 import org.apache.usergrid.persistence.queue.NoAWSCredsRule;
@@ -107,14 +104,14 @@ public class BufferQueueSQSImplTest {
 
 
         //de-index request
-        final DeIndexRequest deIndexRequest1 = new DeIndexRequest( new String[]{"index1.1, index1.2"}, applicationScope, new IndexScopeImpl(new SimpleId("testId3"),"name3"),  new SimpleId("id3"), UUID.randomUUID() );
+        final DeIndexRequest deIndexRequest1 = new DeIndexRequest( new String[]{"index1.1, index1.2"}, applicationScope, new SearchEdgeImpl(new SimpleId("testId3"),"name3"),  new SimpleId("id3"), UUID.randomUUID() );
 
-        final DeIndexRequest deIndexRequest2 = new DeIndexRequest( new String[]{"index2.1", "index2.1"}, applicationScope,  new IndexScopeImpl(new SimpleId("testId4"),"name4"),  new SimpleId("id4"), UUID.randomUUID()  );
+        final DeIndexRequest deIndexRequest2 = new DeIndexRequest( new String[]{"index2.1", "index2.1"}, applicationScope,  new SearchEdgeImpl(new SimpleId("testId4"),"name4"),  new SimpleId("id4"), UUID.randomUUID()  );
 
 
 
 
-        IndexOperationMessage indexOperationMessage = new IndexOperationMessage();
+        IndexIdentifierImpl.IndexOperationMessage indexOperationMessage = new IndexIdentifierImpl.IndexOperationMessage();
         indexOperationMessage.addIndexRequest( indexRequest1);
         indexOperationMessage.addIndexRequest( indexRequest2);
 
@@ -128,11 +125,11 @@ public class BufferQueueSQSImplTest {
 
         //now get it back
 
-        final List<IndexOperationMessage> ops = getResults( 20, TimeUnit.SECONDS );
+        final List<IndexIdentifierImpl.IndexOperationMessage> ops = getResults( 20, TimeUnit.SECONDS );
 
         assertTrue(ops.size() > 0);
 
-        final IndexOperationMessage returnedOperation = ops.get( 0 );
+        final IndexIdentifierImpl.IndexOperationMessage returnedOperation = ops.get( 0 );
 
          //get the operations out
 
@@ -155,10 +152,10 @@ public class BufferQueueSQSImplTest {
 
     }
 
-    private List<IndexOperationMessage> getResults(final long timeout, final TimeUnit timeUnit){
+    private List<IndexIdentifierImpl.IndexOperationMessage> getResults(final long timeout, final TimeUnit timeUnit){
         final long endTime = System.currentTimeMillis() + timeUnit.toMillis( timeout );
 
-        List<IndexOperationMessage> ops;
+        List<IndexIdentifierImpl.IndexOperationMessage> ops;
 
         do{
             ops = bufferQueueSQS.take( 10,  20, TimeUnit.SECONDS );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/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 b28fb54..ac37a61 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
@@ -44,13 +44,14 @@ import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
 import org.apache.usergrid.persistence.core.test.UseModules;
 import org.apache.usergrid.persistence.core.util.Health;
 import org.apache.usergrid.persistence.index.ApplicationEntityIndex;
+import org.apache.usergrid.persistence.index.CandidateResults;
 import org.apache.usergrid.persistence.index.EntityIndex;
 import org.apache.usergrid.persistence.index.EntityIndexBatch;
 import org.apache.usergrid.persistence.index.EntityIndexFactory;
-import org.apache.usergrid.persistence.index.IndexScope;
+import org.apache.usergrid.persistence.index.IndexEdge;
+import org.apache.usergrid.persistence.index.SearchEdge;
 import org.apache.usergrid.persistence.index.SearchTypes;
 import org.apache.usergrid.persistence.index.guice.TestIndexModule;
-import org.apache.usergrid.persistence.index.query.CandidateResults;
 import org.apache.usergrid.persistence.index.utils.UUIDUtils;
 import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.Id;
@@ -107,14 +108,14 @@ public class EntityIndexTest extends BaseIT {
 
 
         final String entityType = "thing";
-        IndexScope indexScope = new IndexScopeImpl( appId, "things" );
+        IndexEdge searchEdge = new IndexEdgeImpl( appId, "things", 1 );
         final SearchTypes searchTypes = SearchTypes.fromTypes( entityType );
 
-        insertJsonBlob( entityIndex, entityType, indexScope, "/sample-large.json", 101, 0 );
+        insertJsonBlob( entityIndex, entityType, searchEdge, "/sample-large.json", 101, 0 );
 
         ei.refresh();
 
-        testQueries( indexScope, searchTypes, entityIndex );
+        testQueries( searchEdge, searchTypes, entityIndex );
     }
 
 
@@ -128,33 +129,33 @@ public class EntityIndexTest extends BaseIT {
         ApplicationEntityIndex entityIndex = eif.createApplicationEntityIndex( applicationScope );
 
         final String entityType = "thing";
-        IndexScope indexScope = new IndexScopeImpl( appId, "things" );
+        IndexEdge indexEdge = new IndexEdgeImpl( appId, "things", 1 );
         final SearchTypes searchTypes = SearchTypes.fromTypes( entityType );
         EntityIndexBatch batch = entityIndex.createBatch();
         Entity entity = new Entity( entityType );
         EntityUtils.setVersion( entity, UUIDGenerator.newTimeUUID() );
         entity.setField( new UUIDField( IndexingUtils.ENTITYID_ID_FIELDNAME, UUID.randomUUID() ) );
         entity.setField( new StringField( "testfield", "test" ) );
-        batch.index( indexScope, entity );
+        batch.index( indexEdge, entity );
         batch.execute().get();
 
         EntityUtils.setVersion( entity, UUIDGenerator.newTimeUUID() );
         List<String> list = new ArrayList<>();
         list.add( "test" );
         entity.setField( new ArrayField<String>( "testfield", list ) );
-        batch.index( indexScope, entity );
+        batch.index( indexEdge, entity );
         batch.execute().get();
 
         EntityUtils.setVersion( entity, UUIDGenerator.newTimeUUID() );
         EntityObject testObj = new EntityObject();
         testObj.setField( new StringField( "test", "testFiedl" ) );
         entity.setField( new EntityObjectField( "testfield", testObj ) );
-        batch.index( indexScope, entity );
+        batch.index( indexEdge, entity );
         batch.execute().get();
 
         ei.refresh();
 
-        testQueries( indexScope, searchTypes, entityIndex );
+        testQueries( indexEdge, searchTypes, entityIndex );
     }
 
 
@@ -168,7 +169,7 @@ public class EntityIndexTest extends BaseIT {
         final int threads = 20;
         final int size = 30;
         final ApplicationEntityIndex entityIndex = eif.createApplicationEntityIndex( applicationScope );
-        final IndexScope indexScope = new IndexScopeImpl( appId, "things" );
+
         final String entityType = "thing";
 
         final CountDownLatch latch = new CountDownLatch( threads );
@@ -177,25 +178,29 @@ public class EntityIndexTest extends BaseIT {
         ObjectMapper mapper = new ObjectMapper();
         final List<Object> sampleJson = mapper.readValue( is, new TypeReference<List<Object>>() {} );
         for ( int i = 0; i < threads; i++ ) {
-            Thread thread = new Thread( new Runnable() {
-                public void run() {
-                    try {
-                        EntityIndexBatch batch = entityIndex.createBatch();
-                        insertJsonBlob( sampleJson, batch, entityType, indexScope, size, 0 );
-                        batch.execute().get();
-                    }
-                    catch ( Exception e ) {
-                        synchronized ( failTime ) {
-                            if ( failTime.get() == 0 ) {
-                                failTime.set( System.currentTimeMillis() );
-                            }
+
+            final IndexEdge indexEdge = new IndexEdgeImpl( appId, "things", i );
+
+            Thread thread = new Thread( () -> {
+                try {
+
+
+
+                    EntityIndexBatch batch = entityIndex.createBatch();
+                    insertJsonBlob( sampleJson, batch, entityType, indexEdge, size, 0 );
+                    batch.execute().get();
+                }
+                catch ( Exception e ) {
+                    synchronized ( failTime ) {
+                        if ( failTime.get() == 0 ) {
+                            failTime.set( System.currentTimeMillis() );
                         }
-                        System.out.println( e.toString() );
-                        fail( "threw exception" );
-                    }
-                    finally {
-                        latch.countDown();
                     }
+                    System.out.println( e.toString() );
+                    fail( "threw exception" );
+                }
+                finally {
+                    latch.countDown();
                 }
             } );
             thread.start();
@@ -234,25 +239,25 @@ public class EntityIndexTest extends BaseIT {
 
 
         final String entityType = "thing";
-        IndexScope indexScope = new IndexScopeImpl( appId, "things" );
+        IndexEdge searchEdge = new IndexEdgeImpl( appId, "things", 10 );
         final SearchTypes searchTypes = SearchTypes.fromTypes( entityType );
 
-        insertJsonBlob( entityIndex, entityType, indexScope, "/sample-large.json", 101, 0 );
+        insertJsonBlob( entityIndex, entityType, searchEdge, "/sample-large.json", 101, 0 );
 
         ei.refresh();
 
-        testQueries( indexScope, searchTypes, entityIndex );
+        testQueries( searchEdge, searchTypes, entityIndex );
 
         ei.addIndex( "v2", 1, 0, "one" );
 
-        insertJsonBlob( entityIndex, entityType, indexScope, "/sample-large.json", 101, 100 );
+        insertJsonBlob( entityIndex, entityType, searchEdge, "/sample-large.json", 101, 100 );
 
         ei.refresh();
 
         //Hilda Youn
-        testQuery( indexScope, searchTypes, entityIndex, "name = 'Hilda Young'", 1 );
+        testQuery( searchEdge, searchTypes, entityIndex, "name = 'Hilda Young'", 1 );
 
-        testQuery( indexScope, searchTypes, entityIndex, "name = 'Lowe Kelley'", 1 );
+        testQuery( searchEdge, searchTypes, entityIndex, "name = 'Lowe Kelley'", 1 );
     }
 
 
@@ -266,45 +271,45 @@ public class EntityIndexTest extends BaseIT {
 
 
         final String entityType = "thing";
-        IndexScope indexScope = new IndexScopeImpl( appId, "things" );
+        IndexEdge searchEdge = new IndexEdgeImpl( appId, "things", 1 );
         final SearchTypes searchTypes = SearchTypes.fromTypes( entityType );
 
-        insertJsonBlob( entityIndex, entityType, indexScope, "/sample-large.json", 1, 0 );
+        insertJsonBlob( entityIndex, entityType, searchEdge, "/sample-large.json", 1, 0 );
 
         ei.refresh();
 
         ei.addIndex( "v2", 1, 0, "one" );
 
-        insertJsonBlob( entityIndex, entityType, indexScope, "/sample-large.json", 1, 0 );
+        insertJsonBlob( entityIndex, entityType, searchEdge, "/sample-large.json", 1, 0 );
 
         ei.refresh();
-        CandidateResults crs = testQuery( indexScope, searchTypes, entityIndex, "name = 'Bowers Oneil'", 2 );
+        CandidateResults crs = testQuery( searchEdge, searchTypes, entityIndex, "name = 'Bowers Oneil'", 2 );
 
         EntityIndexBatch entityIndexBatch = entityIndex.createBatch();
-        entityIndexBatch.deindex( indexScope, crs.get( 0 ) );
-        entityIndexBatch.deindex( indexScope, crs.get( 1 ) );
+        entityIndexBatch.deindex( searchEdge, crs.get( 0 ) );
+        entityIndexBatch.deindex( searchEdge, crs.get( 1 ) );
         entityIndexBatch.execute().get();
         ei.refresh();
 
         //Hilda Youn
-        testQuery( indexScope, searchTypes, entityIndex, "name = 'Bowers Oneil'", 0 );
+        testQuery( searchEdge, searchTypes, entityIndex, "name = 'Bowers Oneil'", 0 );
     }
 
 
-    private void insertJsonBlob( ApplicationEntityIndex entityIndex, String entityType, IndexScope indexScope,
+    private void insertJsonBlob( ApplicationEntityIndex entityIndex, String entityType, IndexEdge indexEdge,
                                  String filePath, final int max, final int startIndex ) throws IOException {
         InputStream is = this.getClass().getResourceAsStream( filePath );
         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, indexEdge, max, startIndex );
         batch.execute().get();
         ei.refresh();
     }
 
 
     private void insertJsonBlob( List<Object> sampleJson, EntityIndexBatch batch, String entityType,
-                                 IndexScope indexScope, final int max, final int startIndex ) throws IOException {
+                                 IndexEdge indexEdge, final int max, final int startIndex ) throws IOException {
         int count = 0;
         StopWatch timer = new StopWatch();
         timer.start();
@@ -324,7 +329,7 @@ public class EntityIndexTest extends BaseIT {
             entity = EntityIndexMapUtils.fromMap( entity, item );
             EntityUtils.setVersion( entity, UUIDGenerator.newTimeUUID() );
             entity.setField( new UUIDField( IndexingUtils.ENTITYID_ID_FIELDNAME, UUID.randomUUID() ) );
-            batch.index( indexScope, entity );
+            batch.index( indexEdge, entity );
             batch.execute().get();
 
 
@@ -346,7 +351,7 @@ public class EntityIndexTest extends BaseIT {
 
         ApplicationScope applicationScope = new ApplicationScopeImpl( appId );
 
-        IndexScope indexScope = new IndexScopeImpl( appId, "fastcars" );
+        IndexEdge searchEdge = new IndexEdgeImpl( appId, "fastcars", 1 );
 
         ApplicationEntityIndex entityIndex = eif.createApplicationEntityIndex( applicationScope );
 
@@ -363,27 +368,27 @@ public class EntityIndexTest extends BaseIT {
         EntityUtils.setVersion( entity, UUIDGenerator.newTimeUUID() );
         entity.setField( new UUIDField( IndexingUtils.ENTITYID_ID_FIELDNAME, UUID.randomUUID() ) );
 
-        entityIndex.createBatch().index( indexScope, entity ).execute().get();
+        entityIndex.createBatch().index( searchEdge, entity ).execute().get();
         ei.refresh();
 
         CandidateResults candidateResults = entityIndex
-                .search( indexScope, SearchTypes.fromTypes( entity.getId().getType() ), "name contains 'Ferrari*'",
+                .search( searchEdge, SearchTypes.fromTypes( entity.getId().getType() ), "name contains 'Ferrari*'",
                         10 );
         assertEquals( 1, candidateResults.size() );
 
         EntityIndexBatch batch = entityIndex.createBatch();
-        batch.deindex( indexScope, entity ).execute().get();
+        batch.deindex( searchEdge, entity ).execute().get();
         batch.execute().get();
         ei.refresh();
 
         candidateResults = entityIndex
-                .search( indexScope, SearchTypes.fromTypes( entity.getId().getType() ), "name contains 'Ferrari*'",
+                .search( searchEdge, SearchTypes.fromTypes( entity.getId().getType() ), "name contains 'Ferrari*'",
                         10 );
         assertEquals( 0, candidateResults.size() );
     }
 
 
-    private CandidateResults testQuery( final IndexScope scope, final SearchTypes searchTypes,
+    private CandidateResults testQuery( final SearchEdge scope, final SearchTypes searchTypes,
                                         final ApplicationEntityIndex entityIndex, final String queryString,
                                         final int num ) {
 
@@ -400,7 +405,7 @@ public class EntityIndexTest extends BaseIT {
     }
 
 
-    private void testQueries( final IndexScope scope, SearchTypes searchTypes,
+    private void testQueries( final SearchEdge scope, SearchTypes searchTypes,
                               final ApplicationEntityIndex entityIndex ) {
 
         testQuery( scope, searchTypes, entityIndex, "name = 'Morgan Pierce'", 1 );
@@ -483,7 +488,7 @@ public class EntityIndexTest extends BaseIT {
 
         ApplicationScope applicationScope = new ApplicationScopeImpl( appId );
 
-        IndexScope appScope = new IndexScopeImpl( ownerId, "user" );
+        IndexEdge indexSCope = new IndexEdgeImpl( ownerId, "user", 10 );
 
         ApplicationEntityIndex entityIndex = eif.createApplicationEntityIndex( applicationScope );
 
@@ -503,23 +508,23 @@ public class EntityIndexTest extends BaseIT {
 
         EntityIndexBatch batch = entityIndex.createBatch();
 
-        batch.index( appScope, user );
+        batch.index( indexSCope, user );
         batch.execute().get();
         ei.refresh();
 
         final String query = "where username = 'edanuff'";
 
-        CandidateResults r = entityIndex.search( appScope, SearchTypes.fromTypes( "edanuff" ), query, 10 );
+        CandidateResults r = entityIndex.search( indexSCope, SearchTypes.fromTypes( "edanuff" ), query, 10 );
         assertEquals( user.getId(), r.get( 0 ).getId() );
 
-        batch.deindex( appScope, user.getId(), user.getVersion() );
+        batch.deindex( indexSCope, user.getId(), user.getVersion() );
         batch.execute().get();
         ei.refresh();
 
         // EntityRef
 
 
-        r = entityIndex.search( appScope, SearchTypes.fromTypes( "edanuff" ), query, 10 );
+        r = entityIndex.search( indexSCope, SearchTypes.fromTypes( "edanuff" ), query, 10 );
 
         assertFalse( r.iterator().hasNext() );
     }
@@ -532,7 +537,7 @@ public class EntityIndexTest extends BaseIT {
         Id ownerId = new SimpleId( "multivaluedtype" );
         ApplicationScope applicationScope = new ApplicationScopeImpl( appId );
 
-        IndexScope appScope = new IndexScopeImpl( ownerId, "user" );
+        IndexEdge indexScope = new IndexEdgeImpl( ownerId, "user", 10 );
 
         ApplicationEntityIndex entityIndex = eif.createApplicationEntityIndex( applicationScope );
 
@@ -552,7 +557,7 @@ public class EntityIndexTest extends BaseIT {
 
         EntityIndexBatch batch = entityIndex.createBatch();
 
-        batch.index( appScope, bill );
+        batch.index( indexScope, bill );
 
         // Fred has age as int, favorites as object and retirement goal as object
         Map fredMap = new HashMap() {{
@@ -572,7 +577,7 @@ public class EntityIndexTest extends BaseIT {
         Entity fred = EntityIndexMapUtils.fromMap( fredMap );
         EntityUtils.setId( fred, new SimpleId( UUIDGenerator.newTimeUUID(), "user" ) );
         EntityUtils.setVersion( fred, UUIDGenerator.newTimeUUID() );
-        batch.index( appScope, fred );
+        batch.index( indexScope, fred );
 
         batch.execute().get();
         ei.refresh();
@@ -580,16 +585,16 @@ public class EntityIndexTest extends BaseIT {
         final SearchTypes searchTypes = SearchTypes.fromTypes( "user" );
 
 
-        CandidateResults r = entityIndex.search( appScope, searchTypes, "where username = 'bill'", 10 );
+        CandidateResults r = entityIndex.search( indexScope, searchTypes, "where username = 'bill'", 10 );
         assertEquals( bill.getId(), r.get( 0 ).getId() );
 
-        r = entityIndex.search( appScope, searchTypes, "where username = 'fred'", 10 );
+        r = entityIndex.search( indexScope, searchTypes, "where username = 'fred'", 10 );
         assertEquals( fred.getId(), r.get( 0 ).getId() );
 
-        r = entityIndex.search( appScope, searchTypes, "where age = 41", 10 );
+        r = entityIndex.search( indexScope, searchTypes, "where age = 41", 10 );
         assertEquals( fred.getId(), r.get( 0 ).getId() );
 
-        r = entityIndex.search( appScope, searchTypes, "where age = 'thirtysomething'", 10 );
+        r = entityIndex.search( indexScope, searchTypes, "where age = 'thirtysomething'", 10 );
         assertEquals( bill.getId(), r.get( 0 ).getId() );
     }
 
@@ -618,7 +623,7 @@ public class EntityIndexTest extends BaseIT {
 
         ApplicationScope applicationScope = new ApplicationScopeImpl( appId );
 
-        IndexScope indexScope = new IndexScopeImpl( ownerId, "users" );
+        IndexEdge indexEdge = new IndexEdgeImpl( ownerId, "users", 10 );
 
 
         ApplicationEntityIndex entityIndex = eif.createApplicationEntityIndex( applicationScope );
@@ -654,7 +659,7 @@ public class EntityIndexTest extends BaseIT {
             entities.add( userId );
 
 
-            batch.index( indexScope, user );
+            batch.index( indexEdge, user );
         }
 
 
@@ -675,8 +680,8 @@ public class EntityIndexTest extends BaseIT {
             final String query = "select * order by created";
 
             final CandidateResults results =
-                    cursor == null ? entityIndex.search( indexScope, SearchTypes.allTypes(), query, limit ) :
-                    entityIndex.getNextPage( cursor, limit );
+                    cursor == null ? entityIndex.search( indexEdge, SearchTypes.allTypes(), query, limit ) :
+                    entityIndex.getNextPage( cursor );
 
             assertTrue( results.hasCursor() );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexLoadTestsIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexLoadTestsIT.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexLoadTestsIT.java
index 64d87d9..035d87f 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexLoadTestsIT.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexLoadTestsIT.java
@@ -38,13 +38,14 @@ import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
 import org.apache.usergrid.persistence.core.test.UseModules;
 import org.apache.usergrid.persistence.index.ApplicationEntityIndex;
+import org.apache.usergrid.persistence.index.CandidateResults;
 import org.apache.usergrid.persistence.index.EntityIndex;
 import org.apache.usergrid.persistence.index.EntityIndexFactory;
-import org.apache.usergrid.persistence.index.IndexScope;
+import org.apache.usergrid.persistence.index.IndexEdge;
+import org.apache.usergrid.persistence.index.SearchEdge;
 import org.apache.usergrid.persistence.index.SearchTypes;
 import org.apache.usergrid.persistence.index.guice.IndexTestFig;
 import org.apache.usergrid.persistence.index.guice.TestIndexModule;
-import org.apache.usergrid.persistence.index.query.CandidateResults;
 import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
@@ -132,7 +133,7 @@ public class IndexLoadTestsIT extends BaseIT {
         final ApplicationScope scope = new ApplicationScopeImpl( applicationId );
 
 
-        final IndexScope indexScope = new IndexScopeImpl( applicationId, "test" );
+        final SearchEdge searchEdge = new SearchEdgeImpl( applicationId, "test" );
 
         batchWriteTPS = metricsFactory.getMeter( IndexLoadTestsIT.class, "write.tps" );
 
@@ -181,7 +182,7 @@ public class IndexLoadTestsIT extends BaseIT {
         final ApplicationScope scope = new ApplicationScopeImpl( applicationId );
 
 
-        final IndexScope indexScope = new IndexScopeImpl( applicationId, "test" );
+        final SearchEdge searchEdge = new SearchEdgeImpl( applicationId, "test" );
 
         final ApplicationEntityIndex appEntityIndex = entityIndexFactory.createApplicationEntityIndex( scope );
 
@@ -190,7 +191,7 @@ public class IndexLoadTestsIT extends BaseIT {
 
         //delay our verification for indexing to happen
         final Observable<DataLoadResult> dataLoadResults =
-            createStreamFromWorkers( appEntityIndex, indexScope, uniqueIdentifier ).buffer( indexTestFig.getBufferSize() )
+            createStreamFromWorkers( appEntityIndex, searchEdge, uniqueIdentifier ).buffer( indexTestFig.getBufferSize() )
                 //perform a delay to let ES index from our batches
                 .delay( indexTestFig.getValidateWait(), TimeUnit.MILLISECONDS )
                     //do our search in parallel, otherwise this test will take far too long
@@ -207,7 +208,7 @@ public class IndexLoadTestsIT extends BaseIT {
 
                         //execute our search
                         final CandidateResults results = appEntityIndex
-                            .search( indexScope, SearchTypes.fromTypes( indexScope.getName() ),
+                            .search( searchEdge, SearchTypes.fromTypes( searchEdge.getEdgeName() ),
                                 "select * where " + FIELD_WORKER_INDEX + "  = " + workerIndex + " AND " + FIELD_ORDINAL
                                     + " = " + ordinal + " AND " + FIELD_UNIQUE_IDENTIFIER + " = '" + uniqueIdentifier
                                     + "'" , 100 );
@@ -257,17 +258,17 @@ public class IndexLoadTestsIT extends BaseIT {
     }
 
 
-    public Observable<Entity> createStreamFromWorkers( final ApplicationEntityIndex entityIndex, final IndexScope indexScope,
+    public Observable<Entity> createStreamFromWorkers( final ApplicationEntityIndex entityIndex, final SearchEdge indexEdge,
                                                        final String uniqueIdentifier ) {
 
         //create a sequence of observables.  Each index will be it's own worker thread using the Schedulers.newthread()
         return Observable.range( 0, indexTestFig.getNumberOfWorkers() ).flatMap(
-            integer -> createWriteObservable( entityIndex, indexScope, uniqueIdentifier, integer )
+            integer -> createWriteObservable( entityIndex, indexEdge, uniqueIdentifier, integer )
                 .subscribeOn( Schedulers.newThread() ) );
     }
 
 
-    private Observable<Entity> createWriteObservable( final ApplicationEntityIndex entityIndex, final IndexScope indexScope,
+    private Observable<Entity> createWriteObservable( final ApplicationEntityIndex entityIndex, final SearchEdge indexEdge,
                                                       final String uniqueIdentifier, final int workerIndex ) {
 
 
@@ -275,7 +276,7 @@ public class IndexLoadTestsIT extends BaseIT {
 
             //create our entity
             .map( integer -> {
-                final Entity entity = new Entity( indexScope.getName() );
+                final Entity entity = new Entity( indexEdge.getEdgeName() );
 
                 entity.setField( new IntegerField( FIELD_WORKER_INDEX, workerIndex ) );
                 entity.setField( new IntegerField( FIELD_ORDINAL, integer ) );
@@ -322,9 +323,13 @@ public class IndexLoadTestsIT extends BaseIT {
                 //buffer up a batch size
             .buffer( indexTestFig.getBufferSize() ).doOnNext( entities -> {
 
+
+               AtomicLong edgeCounter = new AtomicLong(  );
+
                 //take our entities and roll them into a batch
                 Observable.from( entities ).collect( () -> entityIndex.createBatch(), ( entityIndexBatch, entity ) -> {
-                    entityIndexBatch.index( indexScope, entity );
+                    IndexEdge edge = new IndexEdgeImpl( indexEdge.getNodeId(), indexEdge.getEdgeName(), edgeCounter.incrementAndGet()  );
+                    entityIndexBatch.index( edge, entity );
                 } ).doOnNext( entityIndexBatch -> {
                     log.info( "Indexing next {} in batch", entityIndexBatch.size() );
                     //gather the metrics


Mime
View raw message