// Path: src/main/java/org/elasticsearch/ingest/IngestAnalysisService.java
// public static class AnalysisServiceHolder implements Releasable {
//     private final AtomicInteger userCount = new AtomicInteger(1);
//     private final AnalysisService analysisService;
// 
//     public AnalysisServiceHolder(AnalysisService analysisService) {
//         this.analysisService = analysisService;
//     }
// 
//     public void acquire() {
//         userCount.incrementAndGet();
//     }
// 
//     public void release() {
//         if (userCount.decrementAndGet() == 0) {
//             analysisService.close();
//         }
//     }
// 
//     public boolean hasAnalyzer(String analyzerName) {
//         return analysisService.analyzer(analyzerName) != null;
//     }
// 
//     public TokenStream tokenStream(String analyzerName, String fieldName, String text) {
//         Analyzer analyzer = analysisService.analyzer(analyzerName);
//         if (analyzer == null) {
//             throw new IllegalArgumentException("unknown analyzer [" + analyzerName + "]");
//         }
//         return analyzer.tokenStream(fieldName, text);
//     }
// 
//     @Override
//     public void close() {
//         release();
//     }
// }


import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ingest.IngestAnalysisService.AnalysisServiceHolder;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

    String getTargetField() {
        return targetField;
    }

    String getAnalyzer() {
        return analyzer;
    }

    @Override
    public void execute(IngestDocument document) {
        Object oldVal = document.getFieldValue(field, Object.class);
        if (oldVal == null) {
            throw new IllegalArgumentException("field [" + field + "] is null, cannot be analyzed.");
        }
        List<String> tokenList = new ArrayList<>();
        if (oldVal instanceof String) {
            analyze(tokenList, (String) oldVal);
        } else if (oldVal instanceof ArrayList) {
            for (Object obj : (ArrayList) oldVal) {
                analyze(tokenList, obj.toString());
            }
        } else {
            throw new IllegalArgumentException("field [" + field + "] has type [" + oldVal.getClass().getName() +
                    "] and cannot be analyzed");
        }
        document.setFieldValue(targetField, tokenList);
    }

    private void analyze(List<String> tokenList, String val) {
// Path: src/main/java/org/elasticsearch/ingest/IngestAnalysisService.java
// public static class AnalysisServiceHolder implements Releasable {
//     private final AtomicInteger userCount = new AtomicInteger(1);
//     private final AnalysisService analysisService;
// 
//     public AnalysisServiceHolder(AnalysisService analysisService) {
//         this.analysisService = analysisService;
//     }
// 
//     public void acquire() {
//         userCount.incrementAndGet();
//     }
// 
//     public void release() {
//         if (userCount.decrementAndGet() == 0) {
//             analysisService.close();
//         }
//     }
// 
//     public boolean hasAnalyzer(String analyzerName) {
//         return analysisService.analyzer(analyzerName) != null;
//     }
// 
//     public TokenStream tokenStream(String analyzerName, String fieldName, String text) {
//         Analyzer analyzer = analysisService.analyzer(analyzerName);
//         if (analyzer == null) {
//             throw new IllegalArgumentException("unknown analyzer [" + analyzerName + "]");
//         }
//         return analyzer.tokenStream(fieldName, text);
//     }
// 
//     @Override
//     public void close() {
//         release();
//     }
// }


// Path: src/main/java/org/elasticsearch/ingest/AnalyzerProcessor.java
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ingest.IngestAnalysisService.AnalysisServiceHolder;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


    String getTargetField() {
        return targetField;
    }

    String getAnalyzer() {
        return analyzer;
    }

    @Override
    public void execute(IngestDocument document) {
        Object oldVal = document.getFieldValue(field, Object.class);
        if (oldVal == null) {
            throw new IllegalArgumentException("field [" + field + "] is null, cannot be analyzed.");
        }
        List<String> tokenList = new ArrayList<>();
        if (oldVal instanceof String) {
            analyze(tokenList, (String) oldVal);
        } else if (oldVal instanceof ArrayList) {
            for (Object obj : (ArrayList) oldVal) {
                analyze(tokenList, obj.toString());
            }
        } else {
            throw new IllegalArgumentException("field [" + field + "] has type [" + oldVal.getClass().getName() +
                    "] and cannot be analyzed");
        }
        document.setFieldValue(targetField, tokenList);
    }

    private void analyze(List<String> tokenList, String val) {
        AnalysisServiceHolder analysisServiceHolder = ingestAnalysisService.acquireAnalysisServiceHolder();