当前位置: 首页>>代码示例>>Java>>正文


Java Requests.CONTENT_TYPE属性代码示例

本文整理汇总了Java中org.elasticsearch.client.Requests.CONTENT_TYPE属性的典型用法代码示例。如果您正苦于以下问题:Java Requests.CONTENT_TYPE属性的具体用法?Java Requests.CONTENT_TYPE怎么用?Java Requests.CONTENT_TYPE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.elasticsearch.client.Requests的用法示例。


在下文中一共展示了Requests.CONTENT_TYPE属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: should_percolate_with_highlight

@Test
public void should_percolate_with_highlight() throws IOException, ExecutionException, InterruptedException {
    createMapping();

    Requests.CONTENT_TYPE = XContentType.JSON;

    XContentBuilder query = XContentFactory.jsonBuilder()
            .startObject()
            .field("query", matchQuery("message", "bonsai tree"))
            .endObject();
    transportClient.index(Requests.indexRequest(THE_INDEX).type(".percolator").source(query)).actionGet();

    refresh();

    PercolateSourceBuilder.DocBuilder doc = new PercolateSourceBuilder.DocBuilder()
            .setDoc(XContentFactory.jsonBuilder().startObject().field("message", "A new bonsai tree in the office").endObject());
    PercolateRequest request = new PercolateRequest().indices(THE_INDEX).documentType("my-type")
            .source(new PercolateSourceBuilder().setTrackScores(true).setDoc(doc)
                    .setHighlightBuilder(new HighlightBuilder()
                            .field("message").preTags("<foo>").postTags("<bar>")).setSize(5));

    PercolateResponse response = httpClient.percolate(request).get();

    Assertions.assertThat(response.getTotal()).isEqualTo(1);
    Assertions.assertThat(response.getMatches()).hasSize(1);

    Assertions.assertThat(response.getMatches()).hasSize(1);
    Map<String, Highlight> highlight = response.getMatches().getMatches().get(0).getHighlights();
    Assertions.assertThat(highlight).isNotNull().hasSize(1);
    Assertions.assertThat(highlight.get("message").getValue()).contains("<foo>").contains("<bar>").contains("bonsai").contains("tree");
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:31,代码来源:PercolateActionHandlerTest.java

示例2: should_percolate_with_highlight

@Test
public void should_percolate_with_highlight() throws IOException, ExecutionException, InterruptedException {
    createMapping();

    Requests.CONTENT_TYPE = XContentType.JSON;

    XContentBuilder query = XContentFactory.jsonBuilder()
            .startObject()
            .field("query", matchQuery("message", "bonsai tree"))
            .endObject();
    transportClient.index(Requests.indexRequest(THE_INDEX).type(".percolator").source(query)).actionGet();

    refresh();

    PercolateSourceBuilder.DocBuilder doc = new PercolateSourceBuilder.DocBuilder()
            .setDoc(XContentFactory.jsonBuilder().startObject().field("message", "A new bonsai tree in the office").endObject());
    PercolateRequest request = new PercolateRequest().indices(THE_INDEX).documentType("my-type")
            .source(new PercolateSourceBuilder().setTrackScores(true).setDoc(doc)
                    .setHighlightBuilder(new HighlightBuilder()
                            .field("message").preTags("<foo>").postTags("<bar>")).setSize(5));

    MultiPercolateRequest multiPercolateRequest = new MultiPercolateRequest().add(request);

    MultiPercolateResponse response = httpClient.multiPercolate(multiPercolateRequest).get();

    Assertions.assertThat(response.all()).hasSize(1);
    Assertions.assertThat(response.errors()).hasSize(0);

    PercolateResponse percolateResponse = response.percolated().get(0);
    Assertions.assertThat(percolateResponse.getTotal()).isEqualTo(1);
    Assertions.assertThat(percolateResponse.getMatches()).hasSize(1);

    Assertions.assertThat(percolateResponse.getMatches()).hasSize(1);
    Map<String, Highlight> highlight = percolateResponse.getMatches().getMatches().get(0).getHighlights();
    Assertions.assertThat(highlight).isNotNull().hasSize(1);
    Assertions.assertThat(highlight.get("message").getValue()).contains("<foo>").contains("<bar>").contains("bonsai").contains("tree");
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:37,代码来源:MultiPercolateActionHandlerTest.java

示例3: setContentType

@BeforeClass
public static void setContentType() throws Exception {
    Requests.CONTENT_TYPE = randomFrom(XContentType.values());
    Requests.INDEX_CONTENT_TYPE = randomFrom(XContentType.values());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:ESTestCase.java

示例4: restoreContentType

@AfterClass
public static void restoreContentType() {
    Requests.CONTENT_TYPE = XContentType.SMILE;
    Requests.INDEX_CONTENT_TYPE = XContentType.JSON;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:ESTestCase.java

示例5: ToXContentToBytes

protected ToXContentToBytes() {
    this.defaultType = Requests.CONTENT_TYPE;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:3,代码来源:ToXContentToBytes.java

示例6: save_request_content_type

@Before
public void save_request_content_type() {
    // this client only uses JSON, so set the content type used by ES on request generation, but also clean up stuff afterwards
    initialContentType = Requests.CONTENT_TYPE;
    Requests.CONTENT_TYPE = JSON;
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:6,代码来源:AbstractTest.java

示例7: restore_request_content_type

@After
public void restore_request_content_type() {
    Requests.CONTENT_TYPE = initialContentType;
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:4,代码来源:AbstractTest.java


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