lib/src/kbasesearchengine/search/ElasticIndexingStorage.java
private int updateLastVersionsInData(String indexName, GUID parentGUID,
            int lastVersion) throws IOException, IndexingConflictException {

        indexName = getGeneralIndexName(indexName);

        // query = {"bool": {"filter": [{"term": {"prefix": prefix}}]}}
        Map<String, Object> query = ImmutableMap.of("bool",
                                       ImmutableMap.of("filter",
                                               Arrays.asList(ImmutableMap.of("term",
                                                       ImmutableMap.of("prefix",
                                                               toGUIDPrefix(parentGUID))))));

        // params = {"lastver": lastVersion}
        final Map<String, Object> params = ImmutableMap.of("lastver", lastVersion);

        // script = {"source": "ctx._source.islast = (ctx._source.version == params.lastver)",
        //           "params": {"lastver": lastVersion}}
        Map<String, Object> script = ImmutableMap.of(
                "source", "ctx._source.islast = (ctx._source.version == params.lastver);",
                "params", params);

        // doc = {"query": {"bool": {"filter": [{"term": {"prefix": prefix}}]}},
        //        "script": {"source": "ctx._source.islast = (ctx._source.version == params.lastver)",
        //                   "params": {"lastver": lastVersion}}}
        Map<String, Object> doc = ImmutableMap.of("query", query,
                                                  "script", script);

        String urlPath = "/" + indexName + "/" + getDataTableName() + "/_update_by_query?refresh=wait_for";
        Response resp = makeRequest("POST", urlPath, doc);
        @SuppressWarnings("unchecked")
        Map<String, Object> data = UObject.getMapper().readValue(
                resp.getEntity().getContent(), Map.class);
        return (Integer)data.get("updated");
    }
/** This method forces a refresh that is required mainly for sub-objects.
     * The reason for the forced refresh is as follows:
     * The indexing steps are,
     * 1. _index,
     * 2. get ids of records whose last version field needs to be updated (done with a _search!)
     * 3. _update field in records
     *
     * Here, step 1 occures when the object is indexed (prior to this method call). Steps 2&3
     * occur in the update_by_query call (in this method).
     *
     * The search in step 2 requires the refresh on every bulk indexing and update operation,
     * else we get the version conflict exceptions.
     *
      * @param indexName
     * @param parentGUID
     * @param lastVersion
     * @return
     * @throws IOException
     * @throws IndexingConflictException
     */
This method forces a refresh that is required mainly for sub-objects.
The reason for the forced refresh is as follows:
The indexing steps are,
1.

Here, step 1 occures when the object is indexed (prior to this method call). Steps 2&3
occur in the update_by_query call (in this method).

The search in step 2 requires the refresh on every bulk indexing and update operation,
else we get the version conflict exceptions.


This method forces a refresh that is required mainly for sub - objects . The reason for the forced refresh is as follows : The indexing steps are 1 . Here step 1 occures when the object is indexed ( prior to this method call ) . Steps 2&3 occur in the update_by_query call ( in this method ) . The search in step 2 requires the refresh on every bulk indexing and update operation else we get the version conflict exceptions .
private int updateLastVersionsInData(String indexName, GUID parentGUID,
            int lastVersion) throws IOException, IndexingConflictException {
        indexName = getGeneralIndexName(indexName);
        Map<String, Object> query = ImmutableMap.of("bool",
                                       ImmutableMap.of("filter",
                                               Arrays.asList(ImmutableMap.of("term",
                                                       ImmutableMap.of("prefix",
                                                               toGUIDPrefix(parentGUID))))));
        final Map<String, Object> params = ImmutableMap.of("lastver", lastVersion);
        Map<String, Object> script = ImmutableMap.of(
                "source", "ctx._source.islast = (ctx._source.version == params.lastver);",
                "params", params);
        Map<String, Object> doc = ImmutableMap.of("query", query,
                                                  "script", script);
        String urlPath = "/" + indexName + "/" + getDataTableName() + "/_update_by_query?refresh=wait_for";
        Response resp = makeRequest("POST", urlPath, doc);
        @SuppressWarnings("unchecked")
        Map<String, Object> data = UObject.getMapper().readValue(
                resp.getEntity().getContent(), Map.class);
        return (Integer)data.get("updated");
    }
private int updateLastVersionsInData ( String indexName , GUID parentGUID , int lastVersion ) throws IOException , IndexingConflictException { indexName = getGeneralIndexName ( indexName ) ; Map < String , Object > query = ImmutableMap . of ( "bool" , ImmutableMap . of ( "filter" , Arrays . asList ( ImmutableMap . of ( "term" , ImmutableMap . of ( "prefix" , toGUIDPrefix ( parentGUID ) ) ) ) ) ) ; final Map < String , Object > params = ImmutableMap . of ( "lastver" , lastVersion ) ; Map < String , Object > script = ImmutableMap . of ( "source" , "ctx._source.islast = (ctx._source.version == params.lastver);" , "params" , params ) ; Map < String , Object > doc = ImmutableMap . of ( "query" , query , "script" , script ) ; String urlPath = "/" + indexName + "/" + getDataTableName ( ) + "/_update_by_query?refresh=wait_for" ; Response resp = makeRequest ( "POST" , urlPath , doc ) ; @ SuppressWarnings ( "unchecked" ) Map < String , Object > data = UObject . getMapper ( ) . readValue ( resp . getEntity ( ) . getContent ( ) , Map . class ) ; return ( Integer ) data . get ( "updated" ) ; }
This method forces a refresh that is required mainly for sub-objects.
This method forces a refresh that is required mainly for sub - objects .
// query = {"bool": {"filter": [{"term": {"prefix": prefix}}]}} // params = {"lastver": lastVersion} // script = {"source": "ctx._source.islast = (ctx._source.version == params.lastver)", //           "params": {"lastver": lastVersion}} // doc = {"query": {"bool": {"filter": [{"term": {"prefix": prefix}}]}}, //        "script": {"source": "ctx._source.islast = (ctx._source.version == params.lastver)", //                   "params": {"lastver": lastVersion}}}