本文整理汇总了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");
}
示例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");
}
示例3: setContentType
@BeforeClass
public static void setContentType() throws Exception {
Requests.CONTENT_TYPE = randomFrom(XContentType.values());
Requests.INDEX_CONTENT_TYPE = randomFrom(XContentType.values());
}
示例4: restoreContentType
@AfterClass
public static void restoreContentType() {
Requests.CONTENT_TYPE = XContentType.SMILE;
Requests.INDEX_CONTENT_TYPE = XContentType.JSON;
}
示例5: ToXContentToBytes
protected ToXContentToBytes() {
this.defaultType = Requests.CONTENT_TYPE;
}
示例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;
}
示例7: restore_request_content_type
@After
public void restore_request_content_type() {
Requests.CONTENT_TYPE = initialContentType;
}