• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java AnalyzeRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest的典型用法代码示例。如果您正苦于以下问题:Java AnalyzeRequest类的具体用法?Java AnalyzeRequest怎么用?Java AnalyzeRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AnalyzeRequest类属于org.elasticsearch.action.admin.indices.analyze包,在下文中一共展示了AnalyzeRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testParseXContentForAnalyzeRequest

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; //导入依赖的package包/类
public void testParseXContentForAnalyzeRequest() throws Exception {
    XContentParser content = createParser(XContentFactory.jsonBuilder()
        .startObject()
            .field("text", "THIS IS A TEST")
            .field("tokenizer", "keyword")
            .array("filter", "lowercase")
        .endObject());

    AnalyzeRequest analyzeRequest = new AnalyzeRequest("for test");

    RestAnalyzeAction.buildFromContent(content, analyzeRequest);

    assertThat(analyzeRequest.text().length, equalTo(1));
    assertThat(analyzeRequest.text(), equalTo(new String[]{"THIS IS A TEST"}));
    assertThat(analyzeRequest.tokenizer().name, equalTo("keyword"));
    assertThat(analyzeRequest.tokenFilters().size(), equalTo(1));
    for (AnalyzeRequest.NameOrDefinition filter : analyzeRequest.tokenFilters()) {
        assertThat(filter.name, equalTo("lowercase"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:RestAnalyzeActionTests.java


示例2: testTokenizer

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; //导入依赖的package包/类
@Test
public void testTokenizer() throws Exception {
    AnalyzeRequest analyzeRequest = new AnalyzeRequest();
    analyzeRequest.text("My œsophagus caused a débâcle");
    /**
     * whitespace (空白字符)分词器按空白字符 —— 空格、tabs、换行符等等进行简单拆分
     * letter 分词器 ,采用另外一种策略,按照任何非字符进行拆分
     * standard 分词器使用 Unicode 文本分割算法
     */
    analyzeRequest.addTokenFilter("standard");
    analyzeRequest.addCharFilter("asciifolding");
    ActionFuture<AnalyzeResponse> analyzeResponseActionFuture =  client.admin().indices().analyze(analyzeRequest);
    List<AnalyzeResponse.AnalyzeToken> analyzeTokens =  analyzeResponseActionFuture.actionGet().getTokens();
    for (AnalyzeResponse.AnalyzeToken analyzeToken : analyzeTokens){
        System.out.println(analyzeToken.getTerm());
    }
}
 
开发者ID:felayman,项目名称:elasticsearch-full,代码行数:18,代码来源:AnalyzeDemo.java


示例3: prepareRequest

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {

    AnalyzeRequest analyzeRequest = new AnalyzeRequest(request.param("index"));

    try (XContentParser parser = request.contentOrSourceParamParser()) {
        buildFromContent(parser, analyzeRequest);
    } catch (IOException e) {
        throw new IllegalArgumentException("Failed to parse request body", e);
    }

    return channel -> client.admin().indices().analyze(analyzeRequest, new RestToXContentListener<>(channel));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:RestAnalyzeAction.java


示例4: testParseXContentForAnalyzeRequestWithCustomFilters

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; //导入依赖的package包/类
public void testParseXContentForAnalyzeRequestWithCustomFilters() throws Exception {
    XContentParser content = createParser(XContentFactory.jsonBuilder()
        .startObject()
            .field("text", "THIS IS A TEST")
            .field("tokenizer", "keyword")
            .startArray("filter")
                .value("lowercase")
                .startObject()
                    .field("type", "stop")
                    .array("stopwords", "foo", "buzz")
                .endObject()
            .endArray()
            .startArray("char_filter")
                .startObject()
                    .field("type", "mapping")
                    .array("mappings", "ph => f", "qu => q")
                .endObject()
            .endArray()
        .endObject());

    AnalyzeRequest analyzeRequest = new AnalyzeRequest("for test");

    RestAnalyzeAction.buildFromContent(content, analyzeRequest);

    assertThat(analyzeRequest.text().length, equalTo(1));
    assertThat(analyzeRequest.text(), equalTo(new String[]{"THIS IS A TEST"}));
    assertThat(analyzeRequest.tokenizer().name, equalTo("keyword"));
    assertThat(analyzeRequest.tokenFilters().size(), equalTo(2));
    assertThat(analyzeRequest.tokenFilters().get(0).name, equalTo("lowercase"));
    assertThat(analyzeRequest.tokenFilters().get(1).definition, notNullValue());
    assertThat(analyzeRequest.charFilters().size(), equalTo(1));
    assertThat(analyzeRequest.charFilters().get(0).definition, notNullValue());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:34,代码来源:RestAnalyzeActionTests.java


示例5: testParseXContentForAnalyzeRequestWithUnknownParamThrowsException

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; //导入依赖的package包/类
public void testParseXContentForAnalyzeRequestWithUnknownParamThrowsException() throws Exception {
    AnalyzeRequest analyzeRequest = new AnalyzeRequest("for test");
    XContentParser invalidContent = createParser(XContentFactory.jsonBuilder()
        .startObject()
            .field("text", "THIS IS A TEST")
            .field("unknown", "keyword")
        .endObject());
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
            () -> RestAnalyzeAction.buildFromContent(invalidContent, analyzeRequest));
    assertThat(e.getMessage(), startsWith("Unknown parameter [unknown]"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:RestAnalyzeActionTests.java


示例6: testParseXContentForAnalyzeRequestWithInvalidStringExplainParamThrowsException

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; //导入依赖的package包/类
public void testParseXContentForAnalyzeRequestWithInvalidStringExplainParamThrowsException() throws Exception {
    AnalyzeRequest analyzeRequest = new AnalyzeRequest("for test");
    XContentParser invalidExplain = createParser(XContentFactory.jsonBuilder()
        .startObject()
            .field("explain", "fals")
        .endObject());
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
        () -> RestAnalyzeAction.buildFromContent(invalidExplain, analyzeRequest));
    assertThat(e.getMessage(), startsWith("explain must be either 'true' or 'false'"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:RestAnalyzeActionTests.java


示例7: testNoIndexAnalyzers

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; //导入依赖的package包/类
public void testNoIndexAnalyzers() throws IOException {
    AnalyzeRequest request = new AnalyzeRequest();
    request.analyzer("standard");
    request.text("the quick brown fox");
    AnalyzeResponse analyze = TransportAnalyzeAction.analyze(request, AllFieldMapper.NAME, null, null, registry, environment);
    List<AnalyzeResponse.AnalyzeToken> tokens = analyze.getTokens();
    assertEquals(4, tokens.size());

    request.analyzer(null);
    request.tokenizer("whitespace");
    request.addTokenFilter("lowercase");
    request.addTokenFilter("word_delimiter");
    request.text("the qu1ck brown fox");
    analyze = TransportAnalyzeAction.analyze(request, AllFieldMapper.NAME, null, randomBoolean() ? indexAnalyzers : null, registry, environment);
    tokens = analyze.getTokens();
    assertEquals(6, tokens.size());
    assertEquals("qu", tokens.get(1).getTerm());
    assertEquals("1", tokens.get(2).getTerm());
    assertEquals("ck", tokens.get(3).getTerm());

    request.analyzer(null);
    request.tokenizer("whitespace");
    request.addCharFilter("html_strip");
    request.addTokenFilter("lowercase");
    request.addTokenFilter("word_delimiter");
    request.text("<p>the qu1ck brown fox</p>");
    analyze = TransportAnalyzeAction.analyze(request, AllFieldMapper.NAME, null, randomBoolean() ? indexAnalyzers : null, registry, environment);
    tokens = analyze.getTokens();
    assertEquals(6, tokens.size());
    assertEquals("the", tokens.get(0).getTerm());
    assertEquals("qu", tokens.get(1).getTerm());
    assertEquals("1", tokens.get(2).getTerm());
    assertEquals("ck", tokens.get(3).getTerm());
    assertEquals("brown", tokens.get(4).getTerm());
    assertEquals("fox", tokens.get(5).getTerm());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:37,代码来源:TransportAnalyzeActionTests.java


示例8: testFillsAttributes

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; //导入依赖的package包/类
public void testFillsAttributes() throws IOException {
    AnalyzeRequest request = new AnalyzeRequest();
    request.analyzer("standard");
    request.text("the 1 brown fox");
    AnalyzeResponse analyze = TransportAnalyzeAction.analyze(request, AllFieldMapper.NAME, null, null, registry, environment);
    List<AnalyzeResponse.AnalyzeToken> tokens = analyze.getTokens();
    assertEquals(4, tokens.size());
    assertEquals("the", tokens.get(0).getTerm());
    assertEquals(0, tokens.get(0).getStartOffset());
    assertEquals(3, tokens.get(0).getEndOffset());
    assertEquals(0, tokens.get(0).getPosition());
    assertEquals("<ALPHANUM>", tokens.get(0).getType());

    assertEquals("1", tokens.get(1).getTerm());
    assertEquals(4, tokens.get(1).getStartOffset());
    assertEquals(5, tokens.get(1).getEndOffset());
    assertEquals(1, tokens.get(1).getPosition());
    assertEquals("<NUM>", tokens.get(1).getType());

    assertEquals("brown", tokens.get(2).getTerm());
    assertEquals(6, tokens.get(2).getStartOffset());
    assertEquals(11, tokens.get(2).getEndOffset());
    assertEquals(2, tokens.get(2).getPosition());
    assertEquals("<ALPHANUM>", tokens.get(2).getType());

    assertEquals("fox", tokens.get(3).getTerm());
    assertEquals(12, tokens.get(3).getStartOffset());
    assertEquals(15, tokens.get(3).getEndOffset());
    assertEquals(3, tokens.get(3).getPosition());
    assertEquals("<ALPHANUM>", tokens.get(3).getType());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:TransportAnalyzeActionTests.java


示例9: testGetIndexAnalyserWithoutIndexAnalyzers

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; //导入依赖的package包/类
public void testGetIndexAnalyserWithoutIndexAnalyzers() throws IOException {
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
        () -> TransportAnalyzeAction.analyze(
            new AnalyzeRequest()
                .analyzer("custom_analyzer")
                .text("the qu1ck brown fox-dog"),
            AllFieldMapper.NAME, null, null, registry, environment));
    assertEquals(e.getMessage(), "failed to find global analyzer [custom_analyzer]");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:TransportAnalyzeActionTests.java


示例10: testNonPreBuildTokenFilter

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; //导入依赖的package包/类
public void testNonPreBuildTokenFilter() throws IOException {
    AnalyzeRequest request = new AnalyzeRequest();
    request.tokenizer("whitespace");
    request.addTokenFilter("min_hash");
    request.text("the quick brown fox");
    AnalyzeResponse analyze = TransportAnalyzeAction.analyze(request, AllFieldMapper.NAME, null, indexAnalyzers, registry, environment);
    List<AnalyzeResponse.AnalyzeToken> tokens = analyze.getTokens();
    int default_hash_count = 1;
    int default_bucket_size = 512;
    int default_hash_set_size = 1;
    assertEquals(default_hash_count * default_bucket_size * default_hash_set_size, tokens.size());

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:TransportAnalyzeActionTests.java


示例11: testAnalyze

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; //导入依赖的package包/类
public void testAnalyze() {
    String analyzeShardAction = AnalyzeAction.NAME + "[s]";
    interceptTransportActions(analyzeShardAction);

    AnalyzeRequest analyzeRequest = new AnalyzeRequest(randomIndexOrAlias());
    analyzeRequest.text("text");
    internalCluster().coordOnlyNodeClient().admin().indices().analyze(analyzeRequest).actionGet();

    clearInterceptedActions();
    assertSameIndices(analyzeRequest, analyzeShardAction);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:IndicesRequestIT.java


示例12: handleRequest

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {

    String[] texts = request.paramAsStringArrayOrEmptyIfAll("text");

    AnalyzeRequest analyzeRequest = new AnalyzeRequest(request.param("index"));
    analyzeRequest.text(texts);
    analyzeRequest.analyzer(request.param("analyzer"));
    analyzeRequest.field(request.param("field"));
    analyzeRequest.tokenizer(request.param("tokenizer"));
    analyzeRequest.tokenFilters(request.paramAsStringArray("filter", request.paramAsStringArray("token_filter",
        request.paramAsStringArray("token_filters", request.paramAsStringArray("filters", analyzeRequest.tokenFilters())))));
    analyzeRequest.charFilters(request.paramAsStringArray("char_filter", request.paramAsStringArray("char_filters", analyzeRequest.charFilters())));
    analyzeRequest.explain(request.paramAsBoolean("explain", false));
    analyzeRequest.attributes(request.paramAsStringArray("attributes", analyzeRequest.attributes()));

    if (RestActions.hasBodyContent(request)) {
        XContentType type = RestActions.guessBodyContentType(request);
        if (type == null) {
            if (texts == null || texts.length == 0) {
                texts = new String[]{ RestActions.getRestContent(request).toUtf8() };
                analyzeRequest.text(texts);
            }
        } else {
            // NOTE: if rest request with xcontent body has request parameters, the parameters does not override xcontent values
            buildFromContent(RestActions.getRestContent(request), analyzeRequest, parseFieldMatcher);
        }
    }

    client.admin().indices().analyze(analyzeRequest, new RestToXContentListener<AnalyzeResponse>(channel));
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:32,代码来源:RestAnalyzeAction.java


示例13: testClientConnection

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; //导入依赖的package包/类
@Test
public void testClientConnection() throws Exception {
    AnalyzeRequest analyzeRequest = new AnalyzeRequest();
    analyzeRequest.text("美女");
    ActionFuture<AnalyzeResponse> analyzeResponseActionFuture = client.admin().indices().analyze(analyzeRequest);
    List<AnalyzeResponse.AnalyzeToken> analyzeTokens =  analyzeResponseActionFuture.actionGet().getTokens();
    for (AnalyzeResponse.AnalyzeToken analyzeToken  : analyzeTokens){
        System.out.println(analyzeToken.getTerm());
    }
}
 
开发者ID:felayman,项目名称:elasticsearch-full,代码行数:11,代码来源:XPackBaseDemo.java


示例14: testElasticsearchTemplateConnection

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; //导入依赖的package包/类
@Test
public void testElasticsearchTemplateConnection() throws Exception {
    AnalyzeRequest analyzeRequest = new AnalyzeRequest();
    analyzeRequest.text("中华人民共和国");
    ActionFuture<AnalyzeResponse> analyzeResponseActionFuture =  elasticsearchTemplate.getClient().admin().indices().analyze(analyzeRequest);
    List<AnalyzeResponse.AnalyzeToken> analyzeTokens =  analyzeResponseActionFuture.actionGet().getTokens();
    for (AnalyzeResponse.AnalyzeToken analyzeToken  : analyzeTokens){
        System.out.println(analyzeToken.getTerm());
    }
}
 
开发者ID:felayman,项目名称:elasticsearch-full,代码行数:11,代码来源:XPackBaseDemo.java


示例15: testClientConnection

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; //导入依赖的package包/类
@Test
public void testClientConnection() throws Exception {
    AnalyzeRequest analyzeRequest = new AnalyzeRequest();
    analyzeRequest.text("中华人民共和国");
    ActionFuture<AnalyzeResponse> analyzeResponseActionFuture = client.admin().indices().analyze(analyzeRequest);
    List<AnalyzeResponse.AnalyzeToken> analyzeTokens =  analyzeResponseActionFuture.actionGet().getTokens();
    for (AnalyzeResponse.AnalyzeToken analyzeToken  : analyzeTokens){
        System.out.println(analyzeToken.getTerm());
    }
}
 
开发者ID:felayman,项目名称:elasticsearch-full,代码行数:11,代码来源:BaseDemo.java


示例16: showAnaylzerText

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; //导入依赖的package包/类
private static void showAnaylzerText(IndicesAdminClient indicesAdminClient,String analyzerName, String text) {
    AnalyzeResponse analyzeResponse = indicesAdminClient.analyze(new AnalyzeRequest(INDEX_NAME).analyzer(analyzerName).text(text)).actionGet();
    List<AnalyzeResponse.AnalyzeToken> token=analyzeResponse.getTokens();
    for (AnalyzeResponse.AnalyzeToken analyzeToken : token) {
        log.info(analyzerName+": {}",analyzeToken.getTerm());
    }

}
 
开发者ID:ggj2010,项目名称:javabase,代码行数:9,代码来源:CrudDemo.java


示例17: analyze

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; //导入依赖的package包/类
/**
 * 分词-无法分词则返回空集合
 * 
 * @param analyzer
 * @param str
 * @return
 */
public static List<String> analyze(String analyzer, String str) {

    AnalyzeResponse ar = null;
    try {
        AnalyzeRequest request = new AnalyzeRequest(str).analyzer(analyzer).index(
                getCurrentValidIndex());
        ar = ESClient.getClient().admin().indices().analyze(request).actionGet();
    } catch (IndexMissingException e) {
        if (!reLoad) {
            synchronized (AnalyzeHelper.class) {
                if (!reLoad) {
                    reLoad = true;
                }
            }
        }
        return analyze(analyzer, str);
    }

    if (ar == null || ar.getTokens() == null || ar.getTokens().size() < 1) {
        return Lists.newArrayList();
    }
    List<String> analyzeTokens = Lists.newArrayList();
    for (AnalyzeToken at : ar.getTokens()) {
        analyzeTokens.add(at.getTerm());
    }
    return analyzeTokens;
}
 
开发者ID:hailin0,项目名称:es-service-parent,代码行数:35,代码来源:AnalyzeHelper.java


示例18: assertAnalyzesTo

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; //导入依赖的package包/类
protected void assertAnalyzesTo(String analyzer, String input, String[] output, int startOffsets[], int endOffsets[], String types[], int posIncrements[]) {
    assertThat(output, notNullValue());
    AnalyzeResponse response = node.client().admin().indices().analyze(new AnalyzeRequest(INDEX, input).analyzer(analyzer)).actionGet();
    if (VERBOSE) {
        try {
            Map<String,String> params = new HashMap<String,String>();
            params.put("format", "text");
            logger.info("Tokens for \""+input+"\": " + response.toXContent(jsonBuilder().startObject(), new ToXContent.MapParams(params)).endObject().string());
        } catch (IOException e) {
            logger.error("Tokens for \""+input+"\": ERROR", e);
        }
    }
    Iterator<AnalyzeResponse.AnalyzeToken> tokens = response.iterator();
    int pos = 0;
    for (int i = 0; i < output.length; i++) {
        assertThat("token "+i+" does not exist", tokens.hasNext());
        AnalyzeResponse.AnalyzeToken token = tokens.next();
        assertThat("term "+i, token.getTerm(), equalTo(output[i]));
        if (startOffsets != null)
            assertThat("startOffset "+i, token.getStartOffset(), equalTo(startOffsets[i]));
        if (endOffsets != null)
            assertThat("endOffset "+i, token.getEndOffset(), equalTo(endOffsets[i]));
        if (types != null)
            assertThat("type "+i, token.getType(), equalTo(types[i]));
        if (posIncrements != null) {
            pos += posIncrements[i];
            assertThat("position "+i, token.getPosition(), equalTo(pos));
        }
    }
}
 
开发者ID:yakaz,项目名称:elasticsearch-analysis-worddelimiter2,代码行数:31,代码来源:BaseESTest.java


示例19: analyze

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; //导入依赖的package包/类
@Override
public ActionFuture<AnalyzeResponse> analyze(final AnalyzeRequest request) {
    return execute(AnalyzeAction.INSTANCE, request);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:AbstractClient.java


示例20: buildFromContent

import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; //导入依赖的package包/类
static void buildFromContent(XContentParser parser, AnalyzeRequest analyzeRequest)
        throws IOException {
    if (parser.nextToken() != XContentParser.Token.START_OBJECT) {
        throw new IllegalArgumentException("Malformed content, must start with an object");
    } else {
        XContentParser.Token token;
        String currentFieldName = null;
        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
            if (token == XContentParser.Token.FIELD_NAME) {
                currentFieldName = parser.currentName();
            } else if (Fields.TEXT.match(currentFieldName) && token == XContentParser.Token.VALUE_STRING) {
                analyzeRequest.text(parser.text());
            } else if (Fields.TEXT.match(currentFieldName) && token == XContentParser.Token.START_ARRAY) {
                List<String> texts = new ArrayList<>();
                while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                    if (token.isValue() == false) {
                        throw new IllegalArgumentException(currentFieldName + " array element should only contain text");
                    }
                    texts.add(parser.text());
                }
                analyzeRequest.text(texts.toArray(new String[texts.size()]));
            } else if (Fields.ANALYZER.match(currentFieldName) && token == XContentParser.Token.VALUE_STRING) {
                analyzeRequest.analyzer(parser.text());
            } else if (Fields.FIELD.match(currentFieldName) && token == XContentParser.Token.VALUE_STRING) {
                analyzeRequest.field(parser.text());
            } else if (Fields.TOKENIZER.match(currentFieldName)) {
                if (token == XContentParser.Token.VALUE_STRING) {
                    analyzeRequest.tokenizer(parser.text());
                } else if (token == XContentParser.Token.START_OBJECT) {
                    analyzeRequest.tokenizer(parser.map());
                } else {
                    throw new IllegalArgumentException(currentFieldName + " should be tokenizer's name or setting");
                }
            } else if (Fields.TOKEN_FILTERS.match(currentFieldName)
                    && token == XContentParser.Token.START_ARRAY) {
                while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                    if (token == XContentParser.Token.VALUE_STRING) {
                        analyzeRequest.addTokenFilter(parser.text());
                    } else if (token == XContentParser.Token.START_OBJECT) {
                        analyzeRequest.addTokenFilter(parser.map());
                    } else {
                        throw new IllegalArgumentException(currentFieldName
                                + " array element should contain filter's name or setting");
                    }
                }
            } else if (Fields.CHAR_FILTERS.match(currentFieldName)
                    && token == XContentParser.Token.START_ARRAY) {
                while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                    if (token == XContentParser.Token.VALUE_STRING) {
                        analyzeRequest.addCharFilter(parser.text());
                    } else if (token == XContentParser.Token.START_OBJECT) {
                        analyzeRequest.addCharFilter(parser.map());
                    } else {
                        throw new IllegalArgumentException(currentFieldName
                                + " array element should contain char filter's name or setting");
                    }
                }
            } else if (Fields.EXPLAIN.match(currentFieldName)) {
                if (parser.isBooleanValue()) {
                    analyzeRequest.explain(parser.booleanValue());
                } else {
                    throw new IllegalArgumentException(currentFieldName + " must be either 'true' or 'false'");
                }
            } else if (Fields.ATTRIBUTES.match(currentFieldName) && token == XContentParser.Token.START_ARRAY) {
                List<String> attributes = new ArrayList<>();
                while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                    if (token.isValue() == false) {
                        throw new IllegalArgumentException(currentFieldName + " array element should only contain attribute name");
                    }
                    attributes.add(parser.text());
                }
                analyzeRequest.attributes(attributes.toArray(new String[attributes.size()]));
            } else {
                throw new IllegalArgumentException("Unknown parameter ["
                        + currentFieldName + "] in request body or parameter is of the wrong type[" + token + "] ");
            }
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:80,代码来源:RestAnalyzeAction.java



注:本文中的org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Property类代码示例发布时间:2022-05-23
下一篇:
Java RouterDescriptor类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap