// 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();
//     }
// 
// }


import crate.elasticsearch.action.searchinto.SearchIntoContext;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.SearchParseElement;
import org.elasticsearch.search.internal.SearchContext;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
package crate.elasticsearch.action.searchinto.parser;



/**
 * parses the targetNode field which looks like
 * <p/>
 * "targetNode": ["host:9300", "host:9301"]
 *  <p/>
 * or
 *  <p/>
 * "targetNode": "host:9300"
 *
 */
public class TargetNodesParseElement implements SearchParseElement {

    private Pattern PATTERN = Pattern.compile("^\\s*(.*?):(\\d+)\\s*$");

    @Override
    public void parse(XContentParser parser, SearchContext context) throws Exception {
        XContentParser.Token token = parser.currentToken();
        if (token == XContentParser.Token.START_ARRAY) {
            boolean added = false;
// 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/TargetNodesParseElement.java
import crate.elasticsearch.action.searchinto.SearchIntoContext;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.SearchParseElement;
import org.elasticsearch.search.internal.SearchContext;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

package crate.elasticsearch.action.searchinto.parser;



/**
 * parses the targetNode field which looks like
 * <p/>
 * "targetNode": ["host:9300", "host:9301"]
 *  <p/>
 * or
 *  <p/>
 * "targetNode": "host:9300"
 *
 */
public class TargetNodesParseElement implements SearchParseElement {

    private Pattern PATTERN = Pattern.compile("^\\s*(.*?):(\\d+)\\s*$");

    @Override
    public void parse(XContentParser parser, SearchContext context) throws Exception {
        XContentParser.Token token = parser.currentToken();
        if (token == XContentParser.Token.START_ARRAY) {
            boolean added = false;
            SearchIntoContext ctx = (SearchIntoContext)context;