usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [05/33] incubator-usergrid git commit: Moved files to reflect their public/internal usage
Date Mon, 13 Apr 2015 19:18:12 GMT
Moved files to reflect their public/internal usage

Updated index and search scopes with new api


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

Branch: refs/heads/two-dot-o-dev
Commit: f1f87b08595921d3b3a989f2ff08a090a85da82b
Parents: 2699dd3
Author: Todd Nine <tnine@apigee.com>
Authored: Thu Apr 2 15:06:04 2015 -0600
Committer: Todd Nine <tnine@apigee.com>
Committed: Thu Apr 2 15:06:04 2015 -0600

----------------------------------------------------------------------
 .../index/ApplicationEntityIndex.java           |  27 +-
 .../persistence/index/CandidateResult.java      |  84 ++++++
 .../persistence/index/CandidateResults.java     | 105 ++++++++
 .../persistence/index/EntityIndexBatch.java     |  21 +-
 .../persistence/index/EntityIndexFactory.java   |  11 +-
 .../usergrid/persistence/index/IndexAlias.java  |  38 ---
 .../persistence/index/IndexBatchBuffer.java     |  36 ---
 .../persistence/index/IndexBufferConsumer.java  |  37 ---
 .../persistence/index/IndexBufferProducer.java  |  37 ---
 .../usergrid/persistence/index/IndexCache.java  |  39 ---
 .../usergrid/persistence/index/IndexEdge.java   |  36 +++
 .../persistence/index/IndexIdentifier.java      |  45 ----
 .../index/IndexOperationMessage.java            | 138 ----------
 .../usergrid/persistence/index/IndexScope.java  |  38 ---
 .../usergrid/persistence/index/SearchEdge.java  |  45 ++++
 .../usergrid/persistence/index/SearchTypes.java |  49 ++--
 .../persistence/index/SelectFieldMapping.java   |  58 ++++
 .../persistence/index/guice/IndexModule.java    |   2 +-
 .../persistence/index/impl/BufferQueue.java     |  10 +-
 .../index/impl/BufferQueueInMemoryImpl.java     |  21 +-
 .../index/impl/BufferQueueSQSImpl.java          |  25 +-
 .../persistence/index/impl/DeIndexRequest.java  |   9 +-
 .../impl/EsApplicationEntityIndexImpl.java      | 268 ++++++++++++-------
 .../index/impl/EsEntityIndexBatchImpl.java      |  33 ++-
 .../index/impl/EsEntityIndexFactoryImpl.java    |   4 +-
 .../index/impl/EsEntityIndexImpl.java           |   7 +-
 .../index/impl/EsIndexBufferConsumerImpl.java   |  13 +-
 .../index/impl/EsIndexBufferProducerImpl.java   |   8 +-
 .../index/impl/FailureMonitorImpl.java          |  26 ++
 .../persistence/index/impl/IndexAlias.java      |  42 +++
 .../index/impl/IndexBufferConsumer.java         |  37 +++
 .../index/impl/IndexBufferProducer.java         |  32 +++
 .../persistence/index/impl/IndexCache.java      |  43 +++
 .../persistence/index/impl/IndexEdgeImpl.java   |  49 ++++
 .../index/impl/IndexIdentifierImpl.java         | 121 ++++++++-
 .../persistence/index/impl/IndexRequest.java    |   9 +-
 .../persistence/index/impl/IndexScopeImpl.java  |  88 ------
 .../persistence/index/impl/IndexingUtils.java   |  36 ++-
 .../persistence/index/impl/SearchEdgeImpl.java  |  51 ++++
 .../impl/SearchRequestBuilderStrategy.java      |  30 +--
 .../migration/EsIndexDataMigrationImpl.java     |   8 +-
 .../index/migration/LegacyIndexIdentifier.java  |   6 +-
 .../index/query/CandidateResult.java            |  74 -----
 .../index/query/CandidateResults.java           |  98 -------
 .../persistence/index/query/ParsedQuery.java    |   1 +
 .../index/query/SelectFieldMapping.java         |  55 ----
 .../index/utils/IndexValidationUtils.java       |  24 +-
 .../index/guice/TestIndexModule.java            |   4 +-
 .../index/impl/BufferQueueSQSImplTest.java      |  17 +-
 .../persistence/index/impl/EntityIndexTest.java | 141 +++++-----
 .../index/impl/IndexLoadTestsIT.java            |  27 +-
 .../index/impl/IndexMigrationTest.java          |  10 +-
 .../persistence/query/tree/GrammarTreeTest.java |   6 +-
 53 files changed, 1171 insertions(+), 1108 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/ApplicationEntityIndex.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/ApplicationEntityIndex.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/ApplicationEntityIndex.java
index 595cd66..81b3028 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/ApplicationEntityIndex.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/ApplicationEntityIndex.java
@@ -20,8 +20,6 @@
 package org.apache.usergrid.persistence.index;
 
 
-import org.apache.usergrid.persistence.index.query.CandidateResults;
-
 import rx.Observable;
 
 /**
@@ -33,22 +31,33 @@ public interface ApplicationEntityIndex {
     /**
      * Create the index batch.
      */
-    public EntityIndexBatch createBatch();
+    EntityIndexBatch createBatch();
 
-    public CandidateResults search(final IndexScope indexScope, final SearchTypes searchTypes, final String query, final int limit);
+    /**
+     * Search on every document in the specified search edge.  Also search by the types if specified
+     * @param searchEdge The edge to search on
+     * @param searchTypes The search types to search
+     * @param query The query to execute
+     * @param limit The limit of values to return
+     * @return
+     */
+    CandidateResults search( final SearchEdge searchEdge, final SearchTypes searchTypes, final String query,
+                             final int limit );
 
 
 
     /**
-     * get next page of results
-     * @param cursor
-     * @return
+     * Get next page of results from a previous cursor.  Note that limit used here should be the same limit as the initial
+     * Cursor.  Failure to do so can result in strange cursor behavior on the response.
+     *
+     * @param cursor The cursor from the original search
+     * @return The next page of candidate results
      */
-    public CandidateResults getNextPage(final String cursor, final int limit);
+    CandidateResults getNextPage( final String cursor);
 
     /**
      * delete all application records
      * @return
      */
-    public Observable deleteApplication();
+    Observable deleteApplication();
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/CandidateResult.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/CandidateResult.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/CandidateResult.java
new file mode 100644
index 0000000..27d5620
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/CandidateResult.java
@@ -0,0 +1,84 @@
+/*
+ *
+ *  *
+ *  * 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;
+
+
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.core.entity.EntityVersion;
+import org.apache.usergrid.persistence.model.entity.Id;
+
+
+/**
+ * An instance of a candidate result
+ */
+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/CandidateResults.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/CandidateResults.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/CandidateResults.java
new file mode 100644
index 0000000..940effc
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/CandidateResults.java
@@ -0,0 +1,105 @@
+/*
+ *
+ *  *
+ *  * 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;
+
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+
+
+/**
+ * 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;
+    private final Collection<SelectFieldMapping> getFieldMappings;
+
+
+    public CandidateResults( List<CandidateResult> candidates,
+                             final Collection<SelectFieldMapping> getFieldMappings ) {
+        this.candidates = candidates;
+        this.getFieldMappings = getFieldMappings;
+    }
+
+
+    public String initializeCursor(){
+        cursor = org.apache.usergrid.persistence.index.utils.StringUtils.sanitizeUUID( UUIDGenerator.newTimeUUID());
+        return cursor;
+    }
+
+
+    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/EntityIndexBatch.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexBatch.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexBatch.java
index 77b6e7a..da05d39 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexBatch.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexBatch.java
@@ -21,7 +21,6 @@ package org.apache.usergrid.persistence.index;/*
 import java.util.UUID;
 
 import org.apache.usergrid.persistence.core.future.BetterFuture;
-import org.apache.usergrid.persistence.index.query.CandidateResult;
 import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.Id;
 
@@ -31,46 +30,46 @@ public interface EntityIndexBatch {
     /**
      * Create index for Entity
      *
-     * @param indexScope The scope for the index
+     * @param indexEdge  The edge to index the document into
      * @param entity     Entity to be indexed.
      */
-    public EntityIndexBatch index(final IndexScope indexScope, final Entity entity);
+    EntityIndexBatch index( final IndexEdge indexEdge, final Entity entity );
 
     /**
      * Remove index of entity
      *
-     * @param scope  The scope for the entity
+     * @param searchEdge  The searchEdge for the entity
      * @param entity Entity to be removed from index.
      */
-    public EntityIndexBatch deindex(final IndexScope scope, final Entity entity);
+    EntityIndexBatch deindex( final SearchEdge searchEdge, final Entity entity );
 
     /**
      * Remove index of entity.
      *
-     * @param scope  The scope to use for removal
+     * @param searchEdge  The searchEdge to use for removal
      * @param result CandidateResult to be removed from index.
      */
-    public EntityIndexBatch deindex(final IndexScope scope, final CandidateResult result);
+    EntityIndexBatch deindex( final SearchEdge searchEdge, final CandidateResult result );
 
     /**
      * Remove index of entity.
      *
-     * @param scope   The scope to remove
+     * @param searchEdge   The searchEdge to remove
      * @param id      Id to be removed from index.
      * @param version Version to be removed from index.
      */
-    public EntityIndexBatch deindex(final IndexScope scope, final Id id, final UUID version);
+    EntityIndexBatch deindex( final SearchEdge searchEdge, final Id id, final UUID version );
 
 
     /**
      * Execute the batch
      * @return future to guarantee execution
      */
-    public BetterFuture execute();
+    BetterFuture execute();
 
     /**
      * Get the number of operations in the batch
      * @return
      */
-    public int size();
+    int size();
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexFactory.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexFactory.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexFactory.java
index 1c594e7..ad2fba2 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexFactory.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexFactory.java
@@ -25,8 +25,15 @@ import com.google.inject.assistedinject.Assisted;
 
 public interface EntityIndexFactory {
 
-    public ApplicationEntityIndex createApplicationEntityIndex(
-        @Assisted ApplicationScope appScope);
+    /**
+     * Create an applicationEntity index for the provided scope
+     * @param appScope
+     * @return
+     */
+    ApplicationEntityIndex createApplicationEntityIndex( ApplicationScope appScope );
 
+    /**
+     * Invalidate the cache of our factory, and force the generation of new entity index instances
+     */
     void invalidate();
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexAlias.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexAlias.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexAlias.java
deleted file mode 100644
index a04f80e..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexAlias.java
+++ /dev/null
@@ -1,38 +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;
-
-/**
- * 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;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexBatchBuffer.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexBatchBuffer.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexBatchBuffer.java
deleted file mode 100644
index d1015a0..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexBatchBuffer.java
+++ /dev/null
@@ -1,36 +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;
-
-import org.apache.usergrid.persistence.core.future.BetterFuture;
-
-/**
- * * Buffer index requests into sets to send,
- */
-public interface IndexBatchBuffer {
-
-    /**
-     * put request into buffer, retu
-     *
-     * @param container
-     */
-    public BetterFuture put(IndexOperationMessage container);
-
-
-
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexBufferConsumer.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexBufferConsumer.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexBufferConsumer.java
deleted file mode 100644
index e0fb8b3..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexBufferConsumer.java
+++ /dev/null
@@ -1,37 +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;
-
-/**
- *  Buffer index requests
- */
-public interface IndexBufferConsumer {
-
-
-    /**
-     * Start the consumer
-     */
-    public void start();
-
-    /**
-     * Stop the consumers
-     */
-    public 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/IndexBufferProducer.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexBufferProducer.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexBufferProducer.java
deleted file mode 100644
index a9e6d6f..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexBufferProducer.java
+++ /dev/null
@@ -1,37 +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;
-
-import org.apache.usergrid.persistence.core.future.BetterFuture;
-import org.apache.usergrid.persistence.index.IndexOperationMessage;
-import rx.Observable;
-import rx.Subscriber;
-
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.BlockingQueue;
-
-/**
- * Produce to index buffer consumer
- */
-public interface IndexBufferProducer {
-
-    BetterFuture put(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/IndexCache.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexCache.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexCache.java
deleted file mode 100644
index e852230..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexCache.java
+++ /dev/null
@@ -1,39 +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;
-
-/**
- * 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/IndexEdge.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexEdge.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexEdge.java
new file mode 100644
index 0000000..145ccba
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexEdge.java
@@ -0,0 +1,36 @@
+/*
+ *
+ *  *
+ *  * 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;
+
+/**
+ * An edge to perform indexing on.
+ */
+public interface IndexEdge extends SearchEdge {
+
+    /**
+     * Get the timestamp on this edge
+     * @return
+     */
+    long getTimestamp();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java
deleted file mode 100644
index f393ee3..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java
+++ /dev/null
@@ -1,45 +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;
-
-/**
- * Identifier for where an index is in underlying server
- */
-public 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/IndexOperationMessage.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexOperationMessage.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexOperationMessage.java
deleted file mode 100644
index 5686e26..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexOperationMessage.java
+++ /dev/null
@@ -1,138 +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;
-
-
-import java.io.Serializable;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.Callable;
-
-import org.apache.usergrid.persistence.core.future.BetterFuture;
-import org.apache.usergrid.persistence.index.impl.DeIndexRequest;
-import org.apache.usergrid.persistence.index.impl.IndexRequest;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-
-
-/**
- * Container for index operations.
- */
-public 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/IndexScope.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexScope.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexScope.java
deleted file mode 100644
index 5b70304..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexScope.java
+++ /dev/null
@@ -1,38 +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;
-
-import org.apache.usergrid.persistence.model.entity.Id;
-
-
-public interface IndexScope {
-
-    /**
-     * @return The name of the index. If you use pluralization for you names vs types,
-     * you must keep the consistent or you will be unable to load data
-     */
-    public String getName();
-
-    /**
-     * @return A uuid that is unique to this context.  It can be any uuid (time uuid preferred). 
-     * Can be an application id if this is indexed in a collection, or the collection owner.  
-     * In a graph structure, this will be the source node in the graph
-     */
-    public Id getOwner();
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchEdge.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchEdge.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchEdge.java
new file mode 100644
index 0000000..b0b0d66
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchEdge.java
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+import org.apache.usergrid.persistence.model.entity.Id;
+
+
+/**
+ * An edge we can search from
+ */
+public interface SearchEdge {
+
+    /**
+     * Get the node id to be indexed.  In the case of a "TARGET" entity location, this would be the sourceId.  In the case of the "SOURCE" entity location, this would be the targetId.
+     * Ultimately this should be the other side of the edge from the entity getting searched
+     * @return
+     */
+    Id getNodeId();
+
+    /**
+     * Get the name of the edge to be used
+     * @return
+     */
+    String getEdgeName();
+
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchTypes.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchTypes.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchTypes.java
index 9970c62..0bfef2c 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchTypes.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchTypes.java
@@ -20,11 +20,10 @@ package org.apache.usergrid.persistence.index;/*
  */
 
 
+import java.util.Arrays;
+
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.index.impl.IndexingUtils;
-import org.apache.usergrid.persistence.model.entity.Id;
-
-import java.util.Arrays;
 
 
 /**
@@ -33,7 +32,7 @@ import java.util.Arrays;
 
 public class SearchTypes {
 
-    private static final SearchTypes ALL_TYPES = new SearchTypes(  );
+    private static final SearchTypes ALL_TYPES = new SearchTypes();
 
     private final String[] types;
 
@@ -41,22 +40,22 @@ public class SearchTypes {
     private SearchTypes( final String... types ) {this.types = types;}
 
 
-    public String[] getTypeNames(ApplicationScope applicationScope) {
-        String[] typeNames = new String[types.length*2];
-        int i =0 ;
-        for(String type : types){
-            typeNames[i++] = IndexingUtils.getType(applicationScope,type);
-            typeNames[i++] = type;
+    /**
+     * Generate our types to search on
+     * @param applicationScope
+     * @return
+     */
+    public String[] getTypeNames( ApplicationScope applicationScope ) {
+        String[] typeNames = new String[types.length];
+        for ( int i = 0; i < types.length; i++ ) {
+            typeNames[i++] = IndexingUtils.getType( applicationScope, types[i] );
         }
         return typeNames;
     }
 
 
-
     /**
      * Create a search that will search on the specified types
-     * @param types
-     * @return
      */
     public static SearchTypes fromTypes( final String... types ) {
         return new SearchTypes( types );
@@ -65,22 +64,19 @@ public class SearchTypes {
 
     /**
      * Get a search that will search all types in the specified context
-     * @return
      */
-    public static SearchTypes allTypes(){
+    public static SearchTypes allTypes() {
         return ALL_TYPES;
     }
 
 
     /**
-     * Create a search type from a potentially nullable set of string.  If they are null, or empty, then allTypes is returned
-     * otherwise the type will be returned
-     * @param types
-     * @return
+     * Create a search type from a potentially nullable set of string.  If they are null, or empty, then allTypes is
+     * returned otherwise the type will be returned
      */
-    public static SearchTypes fromNullableTypes(final String... types){
+    public static SearchTypes fromNullableTypes( final String... types ) {
 
-        if(isEmpty(types) ){
+        if ( isEmpty( types ) ) {
             return allTypes();
         }
 
@@ -90,16 +86,14 @@ public class SearchTypes {
 
     /**
      * Return true if the array is empty, or it's elements contain a null
-     * @param input
-     * @return
      */
-    private static boolean isEmpty(final String[] input){
-        if(input == null || input.length == 0){
+    private static boolean isEmpty( final String[] input ) {
+        if ( input == null || input.length == 0 ) {
             return true;
         }
 
-        for(int i = 0; i < input.length; i ++){
-            if(input[i] == null){
+        for ( int i = 0; i < input.length; i++ ) {
+            if ( input[i] == null ) {
                 return true;
             }
         }
@@ -107,6 +101,7 @@ public class SearchTypes {
         return false;
     }
 
+
     @Override
     public boolean equals( final Object o ) {
         if ( this == o ) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SelectFieldMapping.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SelectFieldMapping.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SelectFieldMapping.java
new file mode 100644
index 0000000..8d0816a
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SelectFieldMapping.java
@@ -0,0 +1,58 @@
+/*
+ *
+ *  *
+ *  * 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;
+
+
+import java.io.Serializable;
+
+
+/**
+ * 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 implements Serializable {
+
+    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/guice/IndexModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/guice/IndexModule.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/guice/IndexModule.java
index 6307382..a68d312 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/guice/IndexModule.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/guice/IndexModule.java
@@ -53,7 +53,7 @@ public abstract class IndexModule extends AbstractModule {
         bind(EntityIndex.class).to(EsEntityIndexImpl.class);
         bind(IndexCache.class).to(EsIndexCacheImpl.class);
 
-        bind(IndexIdentifier.class).to(IndexIdentifierImpl.class);
+        bind(FailureMonitorImpl.IndexIdentifier.class).to(IndexIdentifierImpl.class);
 
 
         bind(IndexBufferProducer.class).to(EsIndexBufferProducerImpl.class);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/BufferQueue.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/BufferQueue.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/BufferQueue.java
index 76b49c2..cb89f64 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/BufferQueue.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/BufferQueue.java
@@ -23,8 +23,6 @@ package org.apache.usergrid.persistence.index.impl;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 
-import org.apache.usergrid.persistence.index.IndexOperationMessage;
-
 
 /**
  * A temporary interface of our buffer Q to decouple of producer and consumer;
@@ -36,7 +34,7 @@ public interface BufferQueue {
      * Other queues may return the future after ack on the offer.  See the implementation documentation for details.
      * @param operation
      */
-    public void offer(final IndexOperationMessage operation);
+    public void offer(final IndexIdentifierImpl.IndexOperationMessage operation);
 
 
     /**
@@ -48,7 +46,7 @@ public interface BufferQueue {
      * @param timeUnit
      * @return A null safe lid
      */
-    public List<IndexOperationMessage> take(final int takeSize, final long timeout, final TimeUnit timeUnit );
+    public List<IndexIdentifierImpl.IndexOperationMessage> take(final int takeSize, final long timeout, final TimeUnit timeUnit );
 
 
     /**
@@ -57,12 +55,12 @@ public interface BufferQueue {
      *
      * @param messages
      */
-    public void ack(final List<IndexOperationMessage> messages);
+    public void ack(final List<IndexIdentifierImpl.IndexOperationMessage> messages);
 
     /**
      * Mark these message as failed.  Set the exception in the future on local operation
      *
      * @param messages
      */
-    public void fail(final List<IndexOperationMessage> messages, final Throwable t);
+    public void fail(final List<IndexIdentifierImpl.IndexOperationMessage> messages, final Throwable t);
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/BufferQueueInMemoryImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/BufferQueueInMemoryImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/BufferQueueInMemoryImpl.java
index b6eaf89..bfaed3d 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/BufferQueueInMemoryImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/BufferQueueInMemoryImpl.java
@@ -27,7 +27,6 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.usergrid.persistence.core.future.BetterFuture;
 import org.apache.usergrid.persistence.index.IndexFig;
-import org.apache.usergrid.persistence.index.IndexOperationMessage;
 
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
@@ -38,7 +37,7 @@ public class BufferQueueInMemoryImpl implements BufferQueue {
 
 
     private final IndexFig fig;
-    private final ArrayBlockingQueue<IndexOperationMessage> messages;
+    private final ArrayBlockingQueue<IndexIdentifierImpl.IndexOperationMessage> messages;
 
 
     @Inject
@@ -49,7 +48,7 @@ public class BufferQueueInMemoryImpl implements BufferQueue {
 
 
     @Override
-    public void offer( final IndexOperationMessage operation ) {
+    public void offer( final IndexIdentifierImpl.IndexOperationMessage operation ) {
         try {
             messages.offer( operation, fig.getQueueOfferTimeout(), TimeUnit.MILLISECONDS );
         }
@@ -60,9 +59,9 @@ public class BufferQueueInMemoryImpl implements BufferQueue {
 
 
     @Override
-    public List<IndexOperationMessage> take( final int takeSize, final long timeout, final TimeUnit timeUnit ) {
+    public List<IndexIdentifierImpl.IndexOperationMessage> take( final int takeSize, final long timeout, final TimeUnit timeUnit ) {
 
-        final List<IndexOperationMessage> response = new ArrayList<>( takeSize );
+        final List<IndexIdentifierImpl.IndexOperationMessage> response = new ArrayList<>( takeSize );
         try {
 
 
@@ -74,7 +73,7 @@ public class BufferQueueInMemoryImpl implements BufferQueue {
             }
 
 
-            final IndexOperationMessage polled = messages.poll( timeout, timeUnit );
+            final IndexIdentifierImpl.IndexOperationMessage polled = messages.poll( timeout, timeUnit );
 
             if ( polled != null ) {
                 response.add( polled );
@@ -93,20 +92,20 @@ public class BufferQueueInMemoryImpl implements BufferQueue {
 
 
     @Override
-    public void ack( final List<IndexOperationMessage> messages ) {
+    public void ack( final List<IndexIdentifierImpl.IndexOperationMessage> messages ) {
         //if we have a future ack it
-        for ( final IndexOperationMessage op : messages ) {
+        for ( final IndexIdentifierImpl.IndexOperationMessage op : messages ) {
             op.done();
         }
     }
 
 
     @Override
-    public void fail( final List<IndexOperationMessage> messages, final Throwable t ) {
+    public void fail( final List<IndexIdentifierImpl.IndexOperationMessage> messages, final Throwable t ) {
 
 
-        for ( final IndexOperationMessage op : messages ) {
-            final BetterFuture<IndexOperationMessage> future = op.getFuture();
+        for ( final IndexIdentifierImpl.IndexOperationMessage op : messages ) {
+            final BetterFuture<IndexIdentifierImpl.IndexOperationMessage> future = op.getFuture();
 
             if ( future != null ) {
                 future.setError( t );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/BufferQueueSQSImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/BufferQueueSQSImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/BufferQueueSQSImpl.java
index b8d162b..fee828f 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/BufferQueueSQSImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/BufferQueueSQSImpl.java
@@ -32,7 +32,6 @@ import org.slf4j.LoggerFactory;
 
 import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
 import org.apache.usergrid.persistence.index.IndexFig;
-import org.apache.usergrid.persistence.index.IndexOperationMessage;
 import org.apache.usergrid.persistence.map.MapManager;
 import org.apache.usergrid.persistence.map.MapManagerFactory;
 import org.apache.usergrid.persistence.map.MapScope;
@@ -125,7 +124,7 @@ public class BufferQueueSQSImpl implements BufferQueue {
 
 
     @Override
-    public void offer( final IndexOperationMessage operation ) {
+    public void offer( final IndexIdentifierImpl.IndexOperationMessage operation ) {
 
         //no op
         if(operation.isEmpty()){
@@ -159,7 +158,7 @@ public class BufferQueueSQSImpl implements BufferQueue {
 
 
     @Override
-    public List<IndexOperationMessage> take( final int takeSize, final long timeout, final TimeUnit timeUnit ) {
+    public List<IndexIdentifierImpl.IndexOperationMessage> take( final int takeSize, final long timeout, final TimeUnit timeUnit ) {
 
         //SQS doesn't support more than 10
 
@@ -175,7 +174,7 @@ public class BufferQueueSQSImpl implements BufferQueue {
 
 
 
-            final List<IndexOperationMessage> response = new ArrayList<>( messages.size() );
+            final List<IndexIdentifierImpl.IndexOperationMessage> response = new ArrayList<>( messages.size() );
 
             final List<String> mapEntries = new ArrayList<>( messages.size() );
 
@@ -208,7 +207,7 @@ public class BufferQueueSQSImpl implements BufferQueue {
                     continue;
                 }
 
-                final IndexOperationMessage messageBody;
+                final IndexIdentifierImpl.IndexOperationMessage messageBody;
 
                 try {
                     messageBody = fromString( payload );
@@ -234,7 +233,7 @@ public class BufferQueueSQSImpl implements BufferQueue {
 
 
     @Override
-    public void ack( final List<IndexOperationMessage> messages ) {
+    public void ack( final List<IndexIdentifierImpl.IndexOperationMessage> messages ) {
 
         //nothing to do
         if ( messages.size() == 0 ) {
@@ -243,7 +242,7 @@ public class BufferQueueSQSImpl implements BufferQueue {
 
         List<QueueMessage> toAck = new ArrayList<>( messages.size() );
 
-        for ( IndexOperationMessage ioe : messages ) {
+        for ( IndexIdentifierImpl.IndexOperationMessage ioe : messages ) {
 
 
             final SqsIndexOperationMessage sqsIndexOperationMessage =   ( SqsIndexOperationMessage ) ioe;
@@ -261,20 +260,20 @@ public class BufferQueueSQSImpl implements BufferQueue {
 
 
     @Override
-    public void fail( final List<IndexOperationMessage> messages, final Throwable t ) {
+    public void fail( final List<IndexIdentifierImpl.IndexOperationMessage> messages, final Throwable t ) {
         //no op, just let it retry after the queue timeout
     }
 
 
     /** Read the object from Base64 string. */
-    private IndexOperationMessage fromString( String s ) throws IOException {
-        IndexOperationMessage o = mapper.readValue( s, IndexOperationMessage.class );
+    private IndexIdentifierImpl.IndexOperationMessage fromString( String s ) throws IOException {
+        IndexIdentifierImpl.IndexOperationMessage o = mapper.readValue( s, IndexIdentifierImpl.IndexOperationMessage.class );
         return o;
     }
 
 
     /** Write the object to a Base64 string. */
-    private String toString( IndexOperationMessage o ) throws IOException {
+    private String toString( IndexIdentifierImpl.IndexOperationMessage o ) throws IOException {
         return mapper.writeValueAsString( o );
     }
 
@@ -285,12 +284,12 @@ public class BufferQueueSQSImpl implements BufferQueue {
     /**
      * The message that subclasses our IndexOperationMessage.  holds a pointer to the original message
      */
-    public class SqsIndexOperationMessage extends IndexOperationMessage {
+    public class SqsIndexOperationMessage extends IndexIdentifierImpl.IndexOperationMessage {
 
         private final QueueMessage message;
 
 
-        public SqsIndexOperationMessage( final QueueMessage message, final IndexOperationMessage source ) {
+        public SqsIndexOperationMessage( final QueueMessage message, final IndexIdentifierImpl.IndexOperationMessage source ) {
             this.message = message;
             this.addAllDeIndexRequest( source.getDeIndexRequests() );
             this.addAllIndexRequest( source.getIndexRequests() );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/DeIndexRequest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/DeIndexRequest.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/DeIndexRequest.java
index 98aa8cf..24ea188 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/DeIndexRequest.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/DeIndexRequest.java
@@ -24,17 +24,14 @@ import java.util.Arrays;
 import java.util.UUID;
 
 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.index.SearchTypes;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.elasticsearch.action.bulk.BulkRequestBuilder;
 import org.elasticsearch.action.delete.DeleteRequestBuilder;
 import org.elasticsearch.client.Client;
 
-import com.fasterxml.jackson.annotation.JsonSubTypes;
 import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
 
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.createContextName;
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.createIndexDocId;
@@ -56,8 +53,8 @@ public class DeIndexRequest implements BatchRequest {
     }
 
 
-    public DeIndexRequest(String[] indexes, ApplicationScope applicationScope, IndexScope indexScope, Id id, UUID version) {
-        String context = createContextName(applicationScope,indexScope);
+    public DeIndexRequest(String[] indexes, ApplicationScope applicationScope, SearchEdge searchEdge, Id id, UUID version) {
+        String context = createContextName(applicationScope, searchEdge );
         this.indexes = indexes;
         this.entityTypes = SearchType.fromId(id).getTypeNames(applicationScope);
         this.documentId =  createIndexDocId(id, version,context);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsApplicationEntityIndexImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsApplicationEntityIndexImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsApplicationEntityIndexImpl.java
index dfe1c85..171f1c7 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsApplicationEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsApplicationEntityIndexImpl.java
@@ -46,18 +46,16 @@ import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.core.util.ValidationUtils;
 import org.apache.usergrid.persistence.index.AliasedEntityIndex;
 import org.apache.usergrid.persistence.index.ApplicationEntityIndex;
+import org.apache.usergrid.persistence.index.CandidateResult;
+import org.apache.usergrid.persistence.index.CandidateResults;
 import org.apache.usergrid.persistence.index.EntityIndexBatch;
-import org.apache.usergrid.persistence.index.IndexAlias;
-import org.apache.usergrid.persistence.index.IndexBufferProducer;
-import org.apache.usergrid.persistence.index.IndexCache;
 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.index.SearchTypes;
-import org.apache.usergrid.persistence.index.query.CandidateResult;
-import org.apache.usergrid.persistence.index.query.CandidateResults;
+import org.apache.usergrid.persistence.index.exceptions.QueryException;
 import org.apache.usergrid.persistence.index.query.ParsedQuery;
 import org.apache.usergrid.persistence.index.query.ParsedQueryBuilder;
+import org.apache.usergrid.persistence.index.utils.IndexValidationUtils;
 import org.apache.usergrid.persistence.map.MapManager;
 import org.apache.usergrid.persistence.map.MapManagerFactory;
 import org.apache.usergrid.persistence.map.MapScope;
@@ -76,15 +74,17 @@ import rx.Observable;
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.APPLICATION_ID_FIELDNAME;
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.SPLITTER;
 
+
 /**
  * Classy class class.
  */
-public class EsApplicationEntityIndexImpl implements ApplicationEntityIndex{
+public class EsApplicationEntityIndexImpl implements ApplicationEntityIndex {
+
+    private static final Logger logger = LoggerFactory.getLogger( EsApplicationEntityIndexImpl.class );
 
-    private static final Logger logger = LoggerFactory.getLogger(EsApplicationEntityIndexImpl.class);
 
     private final ApplicationScope applicationScope;
-    private final IndexIdentifier indexIdentifier;
+    private final FailureMonitorImpl.IndexIdentifier indexIdentifier;
     private final Timer searchTimer;
     private final Timer cursorTimer;
     private final MapManager mapManager;
@@ -99,61 +99,70 @@ public class EsApplicationEntityIndexImpl implements ApplicationEntityIndex{
     private final SearchRequestBuilderStrategy searchRequest;
     private FailureMonitor failureMonitor;
     private final int cursorTimeout;
+
+
     @Inject
-    public EsApplicationEntityIndexImpl(@Assisted ApplicationScope appScope, final AliasedEntityIndex entityIndex,  final IndexFig config,
-                                        final IndexBufferProducer indexBatchBufferProducer, final EsProvider provider,
-                                        final IndexCache indexCache, final MetricsFactory metricsFactory,
-                                        final MapManagerFactory mapManagerFactory, final IndexFig indexFig, final IndexIdentifier indexIdentifier){
+    public EsApplicationEntityIndexImpl( @Assisted ApplicationScope appScope, final AliasedEntityIndex entityIndex,
+                                         final IndexFig config, final IndexBufferProducer indexBatchBufferProducer,
+                                         final EsProvider provider, final IndexCache indexCache,
+                                         final MetricsFactory metricsFactory, final MapManagerFactory mapManagerFactory,
+                                         final IndexFig indexFig,
+                                         final FailureMonitorImpl.IndexIdentifier indexIdentifier ) {
         this.entityIndex = entityIndex;
         this.indexBatchBufferProducer = indexBatchBufferProducer;
         this.indexCache = indexCache;
         this.indexFig = indexFig;
         this.indexIdentifier = indexIdentifier;
-        ValidationUtils.validateApplicationScope(appScope);
+        ValidationUtils.validateApplicationScope( appScope );
         this.applicationScope = appScope;
-        final MapScope mapScope = new MapScopeImpl(appScope.getApplication(), "cursorcache");
-        this.failureMonitor = new FailureMonitorImpl(config, provider);
+        final MapScope mapScope = new MapScopeImpl( appScope.getApplication(), "cursorcache" );
+        this.failureMonitor = new FailureMonitorImpl( config, provider );
         this.esProvider = provider;
 
-        mapManager = mapManagerFactory.createMapManager(mapScope);
-        this.searchTimer = metricsFactory
-            .getTimer(EsApplicationEntityIndexImpl.class, "search.timer");
-        this.cursorTimer = metricsFactory
-            .getTimer(EsApplicationEntityIndexImpl.class, "search.cursor.timer");
+        mapManager = mapManagerFactory.createMapManager( mapScope );
+        this.searchTimer = metricsFactory.getTimer( EsApplicationEntityIndexImpl.class, "search.timer" );
+        this.cursorTimer = metricsFactory.getTimer( EsApplicationEntityIndexImpl.class, "search.cursor.timer" );
         this.cursorTimeout = config.getQueryCursorTimeout();
 
-        this.deleteApplicationTimer = metricsFactory
-            .getTimer(EsApplicationEntityIndexImpl.class, "delete.application");
-        this.deleteApplicationMeter = metricsFactory
-            .getMeter(EsApplicationEntityIndexImpl.class, "delete.application.meter");
+        this.deleteApplicationTimer =
+                metricsFactory.getTimer( EsApplicationEntityIndexImpl.class, "delete.application" );
+        this.deleteApplicationMeter =
+                metricsFactory.getMeter( EsApplicationEntityIndexImpl.class, "delete.application.meter" );
 
         this.alias = indexIdentifier.getAlias();
 
-        this.searchRequest = new SearchRequestBuilderStrategy(esProvider,appScope,alias,cursorTimeout);
-
+        this.searchRequest = new SearchRequestBuilderStrategy( esProvider, appScope, alias, cursorTimeout );
     }
 
+
     @Override
     public EntityIndexBatch createBatch() {
-        EntityIndexBatch batch = new EsEntityIndexBatchImpl(
-            applicationScope, indexBatchBufferProducer, entityIndex, indexIdentifier);
+        EntityIndexBatch batch =
+                new EsEntityIndexBatchImpl( applicationScope, indexBatchBufferProducer, entityIndex, indexIdentifier );
         return batch;
     }
 
+
     @Override
-      public CandidateResults search( final IndexScope indexScope, final SearchTypes searchTypes, final String query,
-                                      final int limit ) {
+    public CandidateResults search( final SearchEdge searchEdge, final SearchTypes searchTypes, final String query,
+                                    final int limit ) {
+
+        IndexValidationUtils.validateSearchEdge( searchEdge );
+        Preconditions.checkNotNull( searchTypes, "searchTypes cannot be null" );
+        Preconditions.checkNotNull( query, "query cannot be null" );
+        Preconditions.checkArgument( limit > 0, "limit must be > 0" );
 
 
         SearchResponse searchResponse;
 
         final ParsedQuery parsedQuery = ParsedQueryBuilder.build( query );
 
-        final SearchRequestBuilder srb = searchRequest.getBuilder(indexScope, searchTypes, parsedQuery,limit);
+        final SearchRequestBuilder srb = searchRequest.getBuilder( searchEdge, searchTypes, parsedQuery, limit );
 
-        if (logger.isDebugEnabled()) {
-            logger.debug("Searching index (read alias): {}\n  scope: {} \n type: {}\n   query: {} ",
-                this.alias.getReadAlias(), indexScope.getOwner(), searchTypes.getTypeNames(applicationScope), srb);
+        if ( logger.isDebugEnabled() ) {
+            logger.debug( "Searching index (read alias): {}\n  nodeId: {}, edgeType: {},  \n type: {}\n   query: {} ",
+                    this.alias.getReadAlias(), searchEdge.getNodeId(), searchEdge.getEdgeName(),
+                    searchTypes.getTypeNames( applicationScope ), srb );
         }
 
         try {
@@ -161,22 +170,26 @@ public class EsApplicationEntityIndexImpl implements ApplicationEntityIndex{
             Timer.Context timeSearch = searchTimer.time();
             searchResponse = srb.execute().actionGet();
             timeSearch.stop();
-        } catch (Throwable t) {
-            logger.error("Unable to communicate with Elasticsearch", t);
-            failureMonitor.fail("Unable to execute batch", t);
+        }
+        catch ( Throwable t ) {
+            logger.error( "Unable to communicate with Elasticsearch", t );
+            failureMonitor.fail( "Unable to execute batch", t );
             throw t;
-
         }
         failureMonitor.success();
 
-        return parseResults(searchResponse, limit);
+        return parseResults( searchResponse, parsedQuery, limit );
     }
 
 
-    public CandidateResults getNextPage(final String cursor, final int limit){
+    public CandidateResults getNextPage( final String cursor ) {
+        Preconditions.checkNotNull( cursor, "cursor is a required argument" );
+
         SearchResponse searchResponse;
 
         String userCursorString = cursor;
+
+        //sanitiztion, we  probably shouldn't do this here, but in the caller
         if ( userCursorString.startsWith( "\"" ) ) {
             userCursorString = userCursorString.substring( 1 );
         }
@@ -185,17 +198,27 @@ public class EsApplicationEntityIndexImpl implements ApplicationEntityIndex{
         }
 
         //now get the cursor from the map  and validate
-        final String esScrollCursor  = mapManager.getString(userCursorString);
+        final String queryStateString = mapManager.getString( userCursorString );
 
-        Preconditions.checkArgument(esScrollCursor != null, "Could not find a cursor for the value '{}' ", esScrollCursor);
 
+        if(queryStateString == null){
+            throw new QueryException( String.format("Could not find a cursor for the value '%s' ", userCursorString ));
+        }
+
+
+
+        //parse the query state
+        final QueryState queryState = QueryState.fromSerialized( queryStateString );
 
+        //parse the query so we can get select terms
+        final ParsedQuery parsedQuery = ParsedQueryBuilder.build( queryState.ql);
 
-        logger.debug( "Executing query with cursor: {} ", esScrollCursor );
 
+        logger.debug( "Executing query with cursor: {} ", queryState.esCursor );
 
-        SearchScrollRequestBuilder ssrb = esProvider.getClient()
-            .prepareSearchScroll(esScrollCursor).setScroll(cursorTimeout + "m");
+
+        SearchScrollRequestBuilder ssrb =
+                esProvider.getClient().prepareSearchScroll( queryState.esCursor ).setScroll( cursorTimeout + "m" );
 
         try {
             //Added For Graphite Metrics
@@ -211,113 +234,164 @@ public class EsApplicationEntityIndexImpl implements ApplicationEntityIndex{
 
 
         failureMonitor.success();
-        return parseResults(searchResponse, limit);
+
+        return parseResults( searchResponse, parsedQuery, queryState.limit );
     }
 
+
     /**
      * Completely delete an index.
      */
     public Observable deleteApplication() {
         deleteApplicationMeter.mark();
-        String idString = IndexingUtils.idString(applicationScope.getApplication());
-        final TermQueryBuilder tqb = QueryBuilders.termQuery(APPLICATION_ID_FIELDNAME, idString);
+        String idString = IndexingUtils.idString( applicationScope.getApplication() );
+        final TermQueryBuilder tqb = QueryBuilders.termQuery( APPLICATION_ID_FIELDNAME, idString );
         final String[] indexes = entityIndex.getUniqueIndexes();
         Timer.Context timer = deleteApplicationTimer.time();
         //Added For Graphite Metrics
-        return Observable.from(indexes)
-            .flatMap(index -> {
-
-                final ListenableActionFuture<DeleteByQueryResponse> response = esProvider.getClient()
-                    .prepareDeleteByQuery(alias.getWriteAlias()).setQuery(tqb).execute();
-
-                response.addListener(new ActionListener<DeleteByQueryResponse>() {
-
-                    @Override
-                    public void onResponse(DeleteByQueryResponse response) {
-                        checkDeleteByQueryResponse(tqb, response);
-                    }
-
-                    @Override
-                    public void onFailure(Throwable e) {
-                        logger.error("failed on delete index", e);
-                    }
-                });
-                return Observable.from(response);
-            })
-            .doOnError( t -> logger.error("Failed on delete application",t))
-            .doOnCompleted(() -> timer.stop());
+        return Observable.from( indexes ).flatMap( index -> {
+
+            final ListenableActionFuture<DeleteByQueryResponse> response =
+                    esProvider.getClient().prepareDeleteByQuery( alias.getWriteAlias() ).setQuery( tqb ).execute();
+
+            response.addListener( new ActionListener<DeleteByQueryResponse>() {
+
+                @Override
+                public void onResponse( DeleteByQueryResponse response ) {
+                    checkDeleteByQueryResponse( tqb, response );
+                }
+
+
+                @Override
+                public void onFailure( Throwable e ) {
+                    logger.error( "failed on delete index", e );
+                }
+            } );
+            return Observable.from( response );
+        } ).doOnError( t -> logger.error( "Failed on delete application", t ) ).doOnCompleted( () -> timer.stop() );
     }
 
+
     /**
      * Validate the response doesn't contain errors, if it does, fail fast at the first error we encounter
      */
-    private void checkDeleteByQueryResponse(
-        final QueryBuilder query, final DeleteByQueryResponse response ) {
+    private void checkDeleteByQueryResponse( final QueryBuilder query, final DeleteByQueryResponse response ) {
 
         for ( IndexDeleteByQueryResponse indexDeleteByQueryResponse : response ) {
             final ShardOperationFailedException[] failures = indexDeleteByQueryResponse.getFailures();
 
             for ( ShardOperationFailedException failedException : failures ) {
-                logger.error( String.format("Unable to delete by query %s. "
-                            + "Failed with code %d and reason %s on shard %s in index %s",
-                        query.toString(),
-                        failedException.status().getStatus(),
-                        failedException.reason(),
-                        failedException.shardId(),
-                        failedException.index() )
-                );
+                logger.error( String.format( "Unable to delete by query %s. "
+                                        + "Failed with code %d and reason %s on shard %s in index %s", query.toString(),
+                                failedException.status().getStatus(), failedException.reason(),
+                                failedException.shardId(), failedException.index() ) );
             }
-
         }
     }
 
 
-
-
-    private CandidateResults parseResults( final SearchResponse searchResponse,final int limit) {
+    /**
+     * Parse the results and return the canddiate results
+     */
+    private CandidateResults parseResults( final SearchResponse searchResponse, final ParsedQuery query,
+                                           final int limit ) {
 
         final SearchHits searchHits = searchResponse.getHits();
         final SearchHit[] hits = searchHits.getHits();
         final int length = hits.length;
 
-        logger.debug("   Hit count: {} Total hits: {}", length, searchHits.getTotalHits());
+        logger.debug( "   Hit count: {} Total hits: {}", length, searchHits.getTotalHits() );
 
-        List<CandidateResult> candidates = new ArrayList<>(length);
+        List<CandidateResult> candidates = new ArrayList<>( length );
 
-        for (SearchHit hit : hits) {
+        for ( SearchHit hit : hits ) {
 
-            String[] idparts = hit.getId().split(SPLITTER);
+            String[] idparts = hit.getId().split( SPLITTER );
             String id = idparts[0];
             String type = idparts[1];
             String version = idparts[2];
 
-            Id entityId = new SimpleId(UUID.fromString(id), type);
+            Id entityId = new SimpleId( UUID.fromString( id ), type );
 
-            candidates.add(new CandidateResult(entityId, UUID.fromString(version)));
+            candidates.add( new CandidateResult( entityId, UUID.fromString( version ) ) );
         }
 
-        final CandidateResults candidateResults = new CandidateResults(candidates);
+        final CandidateResults candidateResults = new CandidateResults( candidates, query.getSelectFieldMappings() );
         final String esScrollCursor = searchResponse.getScrollId();
 
         // >= seems odd.  However if our user reduces expectedSize (limit) on subsequent requests, we can't do that
         //therefor we need to account for the overflow
-        if(esScrollCursor != null && length >= limit) {
-            candidateResults.initializeCursor();
+        if ( esScrollCursor != null && length >= limit ) {
+            final String cursor = candidateResults.initializeCursor();
 
             //now set this into our map module
             final int minutes = indexFig.getQueryCursorTimeout();
 
+            final QueryState state = new QueryState( query.getOriginalQuery(), limit, esScrollCursor );
+
+            final String queryStateSerialized = state.serialize();
+
             //just truncate it, we'll never hit a long value anyway
-            mapManager.putString(candidateResults.getCursor(), esScrollCursor, (int) TimeUnit.MINUTES.toSeconds(minutes));
+            mapManager.putString( candidateResults.getCursor(), queryStateSerialized,
+                    ( int ) TimeUnit.MINUTES.toSeconds( minutes ) );
 
-            logger.debug(" User cursor = {},  Cursor = {} ", candidateResults.getCursor(), esScrollCursor);
+            logger.debug( " User cursor = {},  Cursor = {} ", candidateResults.getCursor(), esScrollCursor );
         }
 
         return candidateResults;
     }
 
 
+    /**
+     * Class to encapsulate our serialized state
+     */
+    private static final class QueryState {
+
+        /**
+         * Our reserved character for constructing our storage string
+         */
+        private static final String STORAGE_DELIM = "_ugdelim_";
+
+        private final String ql;
+
+        private final int limit;
+
+        private final String esCursor;
+
+
+        private QueryState( final String ql, final int limit, final String esCursor ) {
+            this.ql = ql;
+            this.limit = limit;
+            this.esCursor = esCursor;
+        }
+
+
+        /**
+         * Factory to create an instance of our state from the serialized string
+         */
+        public static QueryState fromSerialized( final String input ) {
+
+            final String[] parts = input.split( STORAGE_DELIM );
+
+            Preconditions.checkArgument( parts != null && parts.length == 3,
+                    "there must be 3 parts to the serialized query state" );
+
+
+            return new QueryState( parts[0], Integer.parseInt( parts[1] ), parts[2] );
+        }
+
+
+        public String serialize() {
+
+            StringBuilder storageString = new StringBuilder();
 
+            storageString.append( ql ).append( STORAGE_DELIM );
 
+            storageString.append( limit ).append( STORAGE_DELIM );
 
+            storageString.append( esCursor );
+
+            return storageString.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/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 6fcb5eb..852dee2 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
@@ -27,7 +27,6 @@ import org.slf4j.LoggerFactory;
 
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.core.util.ValidationUtils;
-import org.apache.usergrid.persistence.index.query.CandidateResult;
 import org.apache.usergrid.persistence.index.utils.IndexValidationUtils;
 import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.Id;
@@ -41,18 +40,18 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
     private final ApplicationScope applicationScope;
 
     private final IndexAlias alias;
-    private final IndexIdentifier indexIdentifier;
+    private final FailureMonitorImpl.IndexIdentifier indexIdentifier;
 
     private final IndexBufferProducer indexBatchBufferProducer;
 
     private final AliasedEntityIndex entityIndex;
-    private IndexOperationMessage container;
+    private IndexIdentifierImpl.IndexOperationMessage container;
 
 
 
     public EsEntityIndexBatchImpl(final ApplicationScope applicationScope,
                                   final IndexBufferProducer indexBatchBufferProducer,
-                                  final AliasedEntityIndex entityIndex, IndexIdentifier indexIdentifier ) {
+                                  final AliasedEntityIndex entityIndex, FailureMonitorImpl.IndexIdentifier indexIdentifier ) {
 
         this.applicationScope = applicationScope;
         this.indexBatchBufferProducer = indexBatchBufferProducer;
@@ -60,26 +59,26 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
         this.indexIdentifier = indexIdentifier;
         this.alias = indexIdentifier.getAlias();
         //constrained
-        this.container = new IndexOperationMessage();
+        this.container = new IndexIdentifierImpl.IndexOperationMessage();
     }
 
 
     @Override
-    public EntityIndexBatch index( final IndexScope indexScope, final Entity entity ) {
-        IndexValidationUtils.validateIndexScope( indexScope );
+    public EntityIndexBatch index( final IndexEdge indexEdge, final Entity entity ) {
+        IndexValidationUtils.validateIndexEdge( indexEdge );
         ValidationUtils.verifyEntityWrite( entity );
         ValidationUtils.verifyVersion( entity.getVersion() );
 
         //add app id for indexing
-        container.addIndexRequest(new IndexRequest(alias.getWriteAlias(), applicationScope,indexScope, entity));
+        container.addIndexRequest(new IndexRequest(alias.getWriteAlias(), applicationScope, indexEdge, entity));
         return this;
     }
 
 
     @Override
-    public EntityIndexBatch deindex( final IndexScope indexScope, final Id id, final UUID version) {
+    public EntityIndexBatch deindex( final SearchEdge searchEdge, final Id id, final UUID version) {
 
-        IndexValidationUtils.validateIndexScope( indexScope );
+        IndexValidationUtils.validateSearchEdge( searchEdge );
         ValidationUtils.verifyIdentity(id);
         ValidationUtils.verifyVersion( version );
 
@@ -89,28 +88,28 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
             indexes = new String[]{indexIdentifier.getIndex(null)};
         }
 
-        container.addDeIndexRequest(new DeIndexRequest(indexes, applicationScope,indexScope,id,version));
+        container.addDeIndexRequest(new DeIndexRequest(indexes, applicationScope, searchEdge,id,version));
 
         return this;
     }
 
 
     @Override
-    public EntityIndexBatch deindex( final IndexScope indexScope, final Entity entity ) {
-        return deindex( indexScope, entity.getId(), entity.getVersion() );
+    public EntityIndexBatch deindex( final SearchEdge searchEdge, final Entity entity ) {
+        return deindex( searchEdge, entity.getId(), entity.getVersion() );
     }
 
 
     @Override
-    public EntityIndexBatch deindex( final IndexScope indexScope, final CandidateResult entity ) {
+    public EntityIndexBatch deindex( final SearchEdge searchEdge, final CandidateResult entity ) {
 
-        return deindex( indexScope, entity.getId(), entity.getVersion() );
+        return deindex( searchEdge, entity.getId(), entity.getVersion() );
     }
 
     @Override
     public BetterFuture execute() {
-        IndexOperationMessage tempContainer = container;
-        container = new IndexOperationMessage();
+        IndexIdentifierImpl.IndexOperationMessage tempContainer = container;
+        container = new IndexIdentifierImpl.IndexOperationMessage();
 
         /**
          * No-op, just disregard it

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1f87b08/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexFactoryImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexFactoryImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexFactoryImpl.java
index 78f0e01..648a29d 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexFactoryImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexFactoryImpl.java
@@ -45,7 +45,7 @@ public class EsEntityIndexFactoryImpl implements EntityIndexFactory{
     private final MapManagerFactory mapManagerFactory;
     private final IndexFig indexFig;
     private final AliasedEntityIndex entityIndex;
-    private final IndexIdentifier indexIdentifier;
+    private final FailureMonitorImpl.IndexIdentifier indexIdentifier;
 
     private LoadingCache<ApplicationScope, ApplicationEntityIndex> eiCache =
         CacheBuilder.newBuilder().maximumSize( 1000 ).build( new CacheLoader<ApplicationScope, ApplicationEntityIndex>() {
@@ -60,7 +60,7 @@ public class EsEntityIndexFactoryImpl implements EntityIndexFactory{
     public EsEntityIndexFactoryImpl( final IndexFig config, final EsProvider provider, final IndexCache indexCache,
                                      final IndexBufferProducer indexBatchBufferProducer,
                                      final MetricsFactory metricsFactory, final MapManagerFactory mapManagerFactory,
-                                     final IndexFig indexFig, final AliasedEntityIndex entityIndex, final IndexIdentifier indexIdentifier ){
+                                     final IndexFig indexFig, final AliasedEntityIndex entityIndex, final FailureMonitorImpl.IndexIdentifier indexIdentifier ){
         this.config = config;
         this.provider = provider;
         this.indexCache = indexCache;


Mime
View raw message