本文整理汇总了Java中org.elasticsearch.action.search.SearchAction.INSTANCE属性的典型用法代码示例。如果您正苦于以下问题:Java SearchAction.INSTANCE属性的具体用法?Java SearchAction.INSTANCE怎么用?Java SearchAction.INSTANCE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.elasticsearch.action.search.SearchAction
的用法示例。
在下文中一共展示了SearchAction.INSTANCE属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mostRecentDocument
public Long mostRecentDocument(String index) {
if (client() == null) {
return null;
}
SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client(), SearchAction.INSTANCE);
SortBuilder sort = SortBuilders.fieldSort("_timestamp").order(SortOrder.DESC);
SearchResponse searchResponse = searchRequestBuilder.setIndices(index).addField("_timestamp").setSize(1).addSort(sort).execute().actionGet();
if (searchResponse.getHits().getHits().length == 1) {
SearchHit hit = searchResponse.getHits().getHits()[0];
if (hit.getFields().get("_timestamp") != null) {
return hit.getFields().get("_timestamp").getValue();
} else {
return 0L;
}
}
return null;
}
示例2: searchData
private SearchResponse searchData(String[] urlItems, String query, int size) {
final SearchRequestBuilder reqBuilder = new SearchRequestBuilder(
client, SearchAction.INSTANCE);
reqBuilder.setIndices();
if (urlItems.length >= 1) {
reqBuilder.setIndices(StringUtils.split(urlItems[0], ","));
}
if (urlItems.length > 1) {
reqBuilder.setTypes(StringUtils.split(urlItems[1], ","));
}
if (!StringUtils.isEmpty(query)) {
// The query can be either JSON-formatted, nor a Lucene query
// So, try to parse as a JSON => if there is an error, consider the query a Lucene one
try {
final Map source = gson.fromJson(query, Map.class);
reqBuilder.setExtraSource(source);
}
catch (JsonParseException e) {
// This is not a JSON (or maybe not well formatted...)
reqBuilder.setQuery(QueryBuilders.queryStringQuery(query).analyzeWildcard(true));
}
}
reqBuilder.setSize(size);
final SearchResponse response = reqBuilder.get();
return response;
}
示例3: findAllBusinessObjectDefinitions
@Override
public ElasticsearchResponseDto findAllBusinessObjectDefinitions(String indexName, String documentType, Set<String> facetFieldsList)
{
LOGGER.info("Elasticsearch get all business object definition documents from index, indexName={} and documentType={}.", indexName, documentType);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder
.fetchSource(new String[] {DATA_PROVIDER_NAME_SOURCE, DESCRIPTION_SOURCE, DISPLAY_NAME_SOURCE, NAME_SOURCE, NAMESPACE_CODE_SOURCE}, null);
ElasticsearchResponseDto elasticsearchResponseDto = new ElasticsearchResponseDto();
// Create a search request and set the scroll time and scroll size
SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(new ElasticsearchClientImpl(), SearchAction.INSTANCE);
searchRequestBuilder.setIndices(indexName);
searchRequestBuilder.setTypes(documentType)
// .setScroll(new TimeValue(ELASTIC_SEARCH_SCROLL_KEEP_ALIVE_TIME))
//.setSize(ELASTIC_SEARCH_SCROLL_PAGE_SIZE)
.setSource(searchSourceBuilder)
// Set sort options.
// First, sort on business object definition name
// then sort on namespace code
.addSort(SortBuilders.fieldSort(BUSINESS_OBJECT_DEFINITION_SORT_FIELD).order(SortOrder.ASC))
.addSort(SortBuilders.fieldSort(NAMESPACE_CODE_SORT_FIELD).order(SortOrder.ASC));
//Add aggregation builder if facet fields are present
addFacetFieldAggregations(facetFieldsList, elasticsearchResponseDto, searchRequestBuilder, indexName);
elasticsearchResponseDto
.setBusinessObjectDefinitionIndexSearchResponseDtos(scrollSearchResultsIntoBusinessObjectDefinitionDto(searchRequestBuilder, indexName));
return elasticsearchResponseDto;
}
示例4: getIdsInIndex
/**
* The ids in index function will take as arguments the index name and the document type and will return a list of all the ids in the index.
*/
@Override
public final List<String> getIdsInIndex(String indexName, String documentType)
{
// Create an array list for storing the ids
List<String> idList = new ArrayList<>();
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(QueryBuilders.matchAllQuery());
// Create a search request and set the scroll time and scroll size
final SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(new ElasticsearchClientImpl(), SearchAction.INSTANCE);
searchRequestBuilder.setIndices(indexName).setTypes(documentType).setScroll(new TimeValue(ELASTIC_SEARCH_SCROLL_KEEP_ALIVE_TIME))
.setSize(ELASTIC_SEARCH_SCROLL_PAGE_SIZE).setSource(searchSourceBuilder);
// Retrieve the search response
final Search.Builder searchBuilder = new Search.Builder(searchRequestBuilder.toString()).addIndex(indexName);
searchBuilder.setParameter(Parameters.SIZE, ELASTIC_SEARCH_SCROLL_PAGE_SIZE);
searchBuilder.setParameter(Parameters.SCROLL, new TimeValue(ELASTIC_SEARCH_SCROLL_KEEP_ALIVE_TIME).toString());
JestResult jestResult = jestClientHelper.searchExecute(searchBuilder.build());
// While there are hits available, page through the results and add them to the id list
while (jestResult.getSourceAsStringList().size() != 0)
{
for (String jsonString : jestResult.getSourceAsStringList())
{
JsonElement root = new JsonParser().parse(jsonString);
idList.add(root.getAsJsonObject().get("id").getAsString());
}
String scrollId = jestResult.getJsonObject().get("_scroll_id").getAsString();
SearchScroll scroll = new SearchScroll.Builder(scrollId, new TimeValue(ELASTIC_SEARCH_SCROLL_KEEP_ALIVE_TIME).toString()).build();
jestResult = jestClientHelper.searchScrollExecute(scroll);
}
return idList;
}
示例5: SimpleRequestBuilder
public SimpleRequestBuilder(ElasticsearchClient client) {
super(client, SimpleAction.INSTANCE, new SimpleRequest());
// here: a built-in query definition, a match all query
SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client, SearchAction.INSTANCE);
searchRequestBuilder
.setQuery(QueryBuilders.matchAllQuery());
request.setSearchRequest(searchRequestBuilder.request());
}
示例6: DeleteByQueryRequestBuilder
public DeleteByQueryRequestBuilder(ElasticsearchClient client,
Action<DeleteByQueryRequest, BulkByScrollResponse, DeleteByQueryRequestBuilder> action) {
this(client, action, new SearchRequestBuilder(client, SearchAction.INSTANCE));
}
示例7: ReindexRequestBuilder
public ReindexRequestBuilder(ElasticsearchClient client,
Action<ReindexRequest, BulkByScrollResponse, ReindexRequestBuilder> action) {
this(client, action, new SearchRequestBuilder(client, SearchAction.INSTANCE),
new IndexRequestBuilder(client, IndexAction.INSTANCE));
}
示例8: UpdateByQueryRequestBuilder
public UpdateByQueryRequestBuilder(ElasticsearchClient client,
Action<UpdateByQueryRequest, BulkByScrollResponse, UpdateByQueryRequestBuilder> action) {
this(client, action, new SearchRequestBuilder(client, SearchAction.INSTANCE));
}
示例9: verifySearch
private void verifySearch(QueryBuilder query, int expectedNumOfDocs) {
SearchRequestBuilder builder = new SearchRequestBuilder(client, SearchAction.INSTANCE);
builder.setQuery(query);
SearchResponse response = client.search(builder.request()).actionGet();
assertEquals(response.getHits().getTotalHits(), expectedNumOfDocs);
}
示例10: CoordinateSearchRequestBuilder
public CoordinateSearchRequestBuilder(final ElasticsearchClient client) {
// hack to be able to subclass SearchRequestBuilder: the action instance is only used in #execute which we overwrite
super(client, SearchAction.INSTANCE);
}
示例11: search
@Override
public ActionResponse search(String[] indices, String[] types, String query, int size) {
final SearchRequestBuilder reqBuilder = new SearchRequestBuilder(
client, SearchAction.INSTANCE);
reqBuilder.setIndices();
if (indices != null) {
reqBuilder.setIndices(indices);
}
if (types != null) {
reqBuilder.setTypes(types);
}
if (!StringUtils.isEmpty(query)) {
// The query can be either JSON-formatted, nor a Lucene query
// So, try to parse as a JSON => if there is an error, consider the query a Lucene one
try {
@SuppressWarnings("rawtypes")
final Map source = gson.fromJson(query, Map.class);
reqBuilder.setExtraSource(source);
}
catch (final JsonSyntaxException e) {
// This is not a JSON (or maybe not well formatted...)
reqBuilder.setQuery(QueryBuilders.queryStringQuery(query).analyzeWildcard(true));
}
}
reqBuilder.setSize(size);
final SearchResponse searchResp = reqBuilder.get();
final ActionResponse actionResp = new ActionResponse()
.succeeded(true)
.totalHits(searchResp.getHits().getTotalHits());
if (searchResp.getAggregations() != null) {
setAggregations(searchResp.getAggregations(), actionResp);
}
else {
for (final SearchHit hit: searchResp.getHits()) {
// Fields can be found either in _source, or in fields (it depends on the query)
// => specific for elasticsearch's version < 5
//
String src = hit.getSourceAsString();
if (src == null) {
final Map<String, Object> hitFields = new HashMap<>();
for (final SearchHitField hitField : hit.getFields().values()) {
hitFields.put(hitField.getName(), hitField.getValues());
}
src = gson.toJson(hitFields);
}
actionResp.addHit(new HitWrapper(hit.getIndex(), hit.getType(), hit.getId(), src));
}
}
return actionResp;
}
示例12: getAction
public SearchAction getAction() {
return SearchAction.INSTANCE;
}