本文整理匯總了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;
}