// Path: src/main/java/crate/elasticsearch/action/searchinto/SearchIntoContext.java
// public class SearchIntoContext extends SearchContext {
// 
//     // currently we only support index targets
//     private String targetType = "index";
// 
//     private List<InetSocketTransportAddress> targetNodes;
// 
// 
//     public Map<String, String> outputNames() {
//         return outputNames;
//     }
// 
//     private final Map<String, String> outputNames = new HashMap<String,
//             String>();
// 
//     public SearchIntoContext(long id, ShardSearchRequest request,
//             SearchShardTarget shardTarget, Engine.Searcher engineSearcher,
//             IndexService indexService, IndexShard indexShard,
//             ScriptService scriptService, CacheRecycler cacheRecycler) {
//         super(id, request, shardTarget, engineSearcher, indexService,
//                 indexShard, scriptService, cacheRecycler);
//     }
// 
//     public String targetType() {
//         // this is currently the only type supported
//         return targetType;
//     }
// 
//     public List<InetSocketTransportAddress> targetNodes() {
//         if (targetNodes == null) {
//             targetNodes = Lists.newArrayList();
//         }
//         return targetNodes;
//     }
// 
//     public void emptyTargetNodes() {
//         this.targetNodes = ImmutableList.of();
//     }
// 
// }
// 
// Path: src/main/java/crate/elasticsearch/action/searchinto/parser/AbstractSearchIntoParser.java
// public abstract class AbstractSearchIntoParser implements ISearchIntoParser {
// 
//     /**
//      * Main method of this class to parse given payload of _search_into action
//      *
//      * @param context
//      * @param source
//      * @throws org.elasticsearch.search.SearchParseException
//      *
//      */
//     public void parseSource(SearchIntoContext context,
//             BytesReference source) throws SearchParseException {
//         XContentParser parser = null;
//         try {
//             if (source != null) {
//                 parser = XContentFactory.xContent(source).createParser(source);
//                 XContentParser.Token token;
//                 while ((token = parser.nextToken()) != XContentParser.Token
//                         .END_OBJECT) {
//                     if (token == XContentParser.Token.FIELD_NAME) {
//                         String fieldName = parser.currentName();
//                         parser.nextToken();
//                         SearchParseElement element = getElementParsers().get(
//                                 fieldName);
//                         if (element == null) {
//                             throw new SearchParseException(context,
//                                     "No parser for element [" + fieldName +
//                                             "]");
//                         }
//                         element.parse(parser, context);
//                     } else if (token == null) {
//                         break;
//                     }
//                 }
//             }
//             validate(context);
//         } catch (Exception e) {
//             String sSource = "_na_";
//             try {
//                 sSource = XContentHelper.convertToJson(source, false);
//             } catch (Throwable e1) {
//                 // ignore
//             }
//             throw new SearchParseException(context,
//                     "Failed to parse source [" + sSource + "]", e);
//         } finally {
//             if (parser != null) {
//                 parser.close();
//             }
//         }
//     }
// 
//     /**
//      * Get the element parser map
//      * @return
//      */
//     protected abstract ImmutableMap<String, SearchParseElement> getElementParsers();
// 
//     /**
//      * Validate the pay load of the search-into context.
//      * @param context
//      */
//     protected void validate(SearchIntoContext context) {
//         if (context.hasFieldNames() && context.fieldNames().contains("_source")) {
//             String index = context.mapperService().index().getName();
//             for (String type : context.mapperService().types()) {
//                 if (!context.mapperService().documentMapper(type).sourceMapper().enabled()) {
//                     throw new SearchParseException(context,
//                             "The _source field of index " + index + " and type " + type + " is not stored.");
//                 }
//             }
//         }
//     }
// }


import java.util.HashMap;
import java.util.Map;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.ImmutableMap;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.search.SearchParseElement;
import org.elasticsearch.search.SearchParseException;
import org.elasticsearch.search.fetch.FetchPhase;
import org.elasticsearch.search.fetch.explain.ExplainParseElement;
import org.elasticsearch.search.query.QueryPhase;
import crate.elasticsearch.action.searchinto.SearchIntoContext;
import crate.elasticsearch.action.searchinto.parser.AbstractSearchIntoParser;
import crate.elasticsearch.action.searchinto.parser.ISearchIntoParser;
package crate.elasticsearch.action.reindex;




/**
 * Parser for pay load given to _reindex action.
 */
public class ReindexParser extends AbstractSearchIntoParser implements ISearchIntoParser {

    private final ImmutableMap<String, SearchParseElement> elementParsers;

    @Inject
    public ReindexParser(QueryPhase queryPhase, FetchPhase fetchPhase) {
        Map<String, SearchParseElement> elementParsers = new HashMap<String,
                SearchParseElement>();
        elementParsers.putAll(queryPhase.parseElements());
        elementParsers.put("explain", new ExplainParseElement());
        this.elementParsers = ImmutableMap.copyOf(elementParsers);
    }

    @Override
    protected ImmutableMap<String, SearchParseElement> getElementParsers() {
        return elementParsers;
    }

    @Override
// Path: src/main/java/crate/elasticsearch/action/searchinto/SearchIntoContext.java
// public class SearchIntoContext extends SearchContext {
// 
//     // currently we only support index targets
//     private String targetType = "index";
// 
//     private List<InetSocketTransportAddress> targetNodes;
// 
// 
//     public Map<String, String> outputNames() {
//         return outputNames;
//     }
// 
//     private final Map<String, String> outputNames = new HashMap<String,
//             String>();
// 
//     public SearchIntoContext(long id, ShardSearchRequest request,
//             SearchShardTarget shardTarget, Engine.Searcher engineSearcher,
//             IndexService indexService, IndexShard indexShard,
//             ScriptService scriptService, CacheRecycler cacheRecycler) {
//         super(id, request, shardTarget, engineSearcher, indexService,
//                 indexShard, scriptService, cacheRecycler);
//     }
// 
//     public String targetType() {
//         // this is currently the only type supported
//         return targetType;
//     }
// 
//     public List<InetSocketTransportAddress> targetNodes() {
//         if (targetNodes == null) {
//             targetNodes = Lists.newArrayList();
//         }
//         return targetNodes;
//     }
// 
//     public void emptyTargetNodes() {
//         this.targetNodes = ImmutableList.of();
//     }
// 
// }
// 
// Path: src/main/java/crate/elasticsearch/action/searchinto/parser/AbstractSearchIntoParser.java
// public abstract class AbstractSearchIntoParser implements ISearchIntoParser {
// 
//     /**
//      * Main method of this class to parse given payload of _search_into action
//      *
//      * @param context
//      * @param source
//      * @throws org.elasticsearch.search.SearchParseException
//      *
//      */
//     public void parseSource(SearchIntoContext context,
//             BytesReference source) throws SearchParseException {
//         XContentParser parser = null;
//         try {
//             if (source != null) {
//                 parser = XContentFactory.xContent(source).createParser(source);
//                 XContentParser.Token token;
//                 while ((token = parser.nextToken()) != XContentParser.Token
//                         .END_OBJECT) {
//                     if (token == XContentParser.Token.FIELD_NAME) {
//                         String fieldName = parser.currentName();
//                         parser.nextToken();
//                         SearchParseElement element = getElementParsers().get(
//                                 fieldName);
//                         if (element == null) {
//                             throw new SearchParseException(context,
//                                     "No parser for element [" + fieldName +
//                                             "]");
//                         }
//                         element.parse(parser, context);
//                     } else if (token == null) {
//                         break;
//                     }
//                 }
//             }
//             validate(context);
//         } catch (Exception e) {
//             String sSource = "_na_";
//             try {
//                 sSource = XContentHelper.convertToJson(source, false);
//             } catch (Throwable e1) {
//                 // ignore
//             }
//             throw new SearchParseException(context,
//                     "Failed to parse source [" + sSource + "]", e);
//         } finally {
//             if (parser != null) {
//                 parser.close();
//             }
//         }
//     }
// 
//     /**
//      * Get the element parser map
//      * @return
//      */
//     protected abstract ImmutableMap<String, SearchParseElement> getElementParsers();
// 
//     /**
//      * Validate the pay load of the search-into context.
//      * @param context
//      */
//     protected void validate(SearchIntoContext context) {
//         if (context.hasFieldNames() && context.fieldNames().contains("_source")) {
//             String index = context.mapperService().index().getName();
//             for (String type : context.mapperService().types()) {
//                 if (!context.mapperService().documentMapper(type).sourceMapper().enabled()) {
//                     throw new SearchParseException(context,
//                             "The _source field of index " + index + " and type " + type + " is not stored.");
//                 }
//             }
//         }
//     }
// }


// Path: src/main/java/crate/elasticsearch/action/reindex/ReindexParser.java
import java.util.HashMap;
import java.util.Map;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.ImmutableMap;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.search.SearchParseElement;
import org.elasticsearch.search.SearchParseException;
import org.elasticsearch.search.fetch.FetchPhase;
import org.elasticsearch.search.fetch.explain.ExplainParseElement;
import org.elasticsearch.search.query.QueryPhase;
import crate.elasticsearch.action.searchinto.SearchIntoContext;
import crate.elasticsearch.action.searchinto.parser.AbstractSearchIntoParser;
import crate.elasticsearch.action.searchinto.parser.ISearchIntoParser;

package crate.elasticsearch.action.reindex;




/**
 * Parser for pay load given to _reindex action.
 */
public class ReindexParser extends AbstractSearchIntoParser implements ISearchIntoParser {

    private final ImmutableMap<String, SearchParseElement> elementParsers;

    @Inject
    public ReindexParser(QueryPhase queryPhase, FetchPhase fetchPhase) {
        Map<String, SearchParseElement> elementParsers = new HashMap<String,
                SearchParseElement>();
        elementParsers.putAll(queryPhase.parseElements());
        elementParsers.put("explain", new ExplainParseElement());
        this.elementParsers = ImmutableMap.copyOf(elementParsers);
    }

    @Override
    protected ImmutableMap<String, SearchParseElement> getElementParsers() {
        return elementParsers;
    }

    @Override
    public void parseSource(SearchIntoContext context, BytesReference source)