elasticsearch-java-api

Query across multiple index in the Elasticsearch version 7.7

折月煮酒 提交于 2020-06-17 09:34:23
问题 In elastic search version 7.7, multiple _types in the index is removed, Now If we want to query across multiple index, we are doing in the following way. /index1,index2/_search?q=type:tweet In 7.7, what is the best way to query from multiple indexes using Transport Java API? Edited : 1) Say I have two indexes, " user " and " tweet " I want to search both the index - user and tweet like below If I want to query the " user " index on the field as {"username" = " Opster "} and in " tweet " index

do we need to close elasticsearch node after the every search request

淺唱寂寞╮ 提交于 2020-04-30 07:52:37
问题 I want to know: do we have to call node.close() every time when we are done with our querying/searching process or just client.close() is fine? Here is my code: val node =nodeBuilder().client(true).node() val client =node.client() val query = QueryBuilders.matchQuery(fieldName.toString(), q).fuzziness(Fuzziness.AUTO)//user can make 2 typo mistakes val response = client.prepareSearch("arteciatedb") .setTypes("readOnlyAdmin") .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) .addFields("uuid",

do we need to close elasticsearch node after the every search request

不打扰是莪最后的温柔 提交于 2020-04-30 07:50:39
问题 I want to know: do we have to call node.close() every time when we are done with our querying/searching process or just client.close() is fine? Here is my code: val node =nodeBuilder().client(true).node() val client =node.client() val query = QueryBuilders.matchQuery(fieldName.toString(), q).fuzziness(Fuzziness.AUTO)//user can make 2 typo mistakes val response = client.prepareSearch("arteciatedb") .setTypes("readOnlyAdmin") .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) .addFields("uuid",

create dummy SearchResponse instance for ElasticSearch test case

时光毁灭记忆、已成空白 提交于 2020-01-28 10:33:10
问题 I'm trying to create a dummy SearchResponse object by passing the values manually to the constructor. I have a JUnit test class for which I'm using this dummy value to mock the actual method call. Trying with the below method to public SearchResponse actionGet() throws ElasticsearchException { ShardSearchFailure[] shardFailures = new ShardSearchFailure[0]; int docId = 0; String id = "5YmRf-6OTvelt29V5dphmw"; Map<String, SearchHitField> fields = null; InternalSearchHit internalSearchHit = new

elasticsearch: return TotalPages not correct

好久不见. 提交于 2020-01-06 02:35:09
问题 I have 107 documents in my index base, i created a method to return all these documents with pagination, in my case the first page contains 20 documents and i logically get 6 pages, the 5 first pages contain 20 documents each and the 6th page contains only 7. The problem is that the methods reeturn always 1 page not 6 @Override @Transactional(readOnly = true) public Page<Convention> findAll(Pageable pageable) throws UnknownHostException { String[] parts = pageable.getSort().toString().split("

How to do multiple filter query in Elasticsearch using Java?

谁说我不能喝 提交于 2020-01-02 06:10:09
问题 I have build a web app on top of elasticsearch. I would like to do a multiple filter using Java. Elasticsearch Query: { "query": { "bool": { "must": [ {"match": { "T": "TEXT"}, "match": { "new_content": "TEXT" } }, ], "filter": { "term": { "collection1": "xyz" }, "term": { "collection2": "abc" } I want to filter the query such that it should filter on the same field collection with two different values(for eg,"xyz" and "abc") Right now, I have coded a Java program for the single filter.

Update By Query in Elasticsearch using Java

余生长醉 提交于 2019-12-28 15:47:06
问题 I’m currently using Elasticsearch V2.3.1. I want to use the following Elasticsearch query in Java. POST /twitter/_update_by_query { "script": { "inline": "ctx._source.List = [‘Item 1’,’Item 2’]” }, "query": { "term": { "user": "kimchy" } } } The above query searches for “user” named “kimchy” and updates the “List” field with given values. This query updates multiple documents at the same time. I read about the Update API for Java here https://www.elastic.co/guide/en/elasticsearch/client/java