elasticsearch-java-api

How to set the query via JSON to an Elasticsearch SearchRequest?

泪湿孤枕 提交于 2019-12-23 08:37:08
问题 Elasticsearch : 6.1.2 I have an input query via JSON and would like to use the high level Java API to construct a search request using that query data. String jsonQuery = "..." SearchRequest searchRequest = new SearchRequest() SearchSourceBuilder builder = ? searchRequest.source(builder); I tried to construct the builder via: SearchSourceBuilder.fromXContent(XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, query)); but that yields: Caused by: org.elasticsearch

How to covert this elastic search functional score query to java API

落花浮王杯 提交于 2019-12-20 03:17:01
问题 How to convert the below ES query to Java API? I am using elastic search 2.3.3 GET /schema_name/_search { "from": 0, "size": 200, "query": { "function_score": { "query": { "match_all": {} }, "boost": "5", "functions": [{ "filter": { "term": { "alert_code": "event_rule_1" } }, "weight": 50 }, { "filter": { "term": { "alert_code": "event_rule_2" } }, "weight": 30 }, { "filter": { "term": { "alert_code": "event_rule_3" } }, "weight": 10 }, { "filter": { "term": { "alert_code": "event_rule_4" } }

Elasticsearch NoNodeAvailableException

Deadly 提交于 2019-12-13 04:14:24
问题 I am getting following error from Elasticsearch. `<html><head><title>Apache Tomcat/7.0.64 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font

SocketTimeoutException while retrieving or inserting data into Elastic Search by using Rest High Level Client

社会主义新天地 提交于 2019-12-12 15:03:43
问题 I'm facing SocketTimeoutException while retrieving/inserting data from/to elastic. This is happening when there are around 10-30 request/second . These requests are combination of get/put. Here is my elastic configuration: 3 master nodes each of 4GB RAM 2 data nodes each of 8GM RAM Azure load balancer which connects to above data node (seems only 9200 port is opened on it). And java client connects to this load balancer as it's only exposed. Elastic Version: 7.2.0 Rest High Level Client:

Elasticsearch update the whole `_source` field based on search query

旧街凉风 提交于 2019-12-11 07:27:43
问题 "_source": { "id": "5b1676493d21784208c36041", "label": "name", "properties": { "name": "patrick" }, "updatedAt": 1528259039542 } I want to update this document based on id (not _id ) with a new document. Something like this: "_source": { "dataSource": "ELASTIC", "entity": "vertices", "label": "vertices", "id": "5b1676493d21784208c36041", "properties": { "name": "patrick" }, "updatedAt": 1528259039542 } elasticsearch version: 6.2, ES Java api: 6.2 回答1: You can achieve what you want using the

Elasticsearch 6.0.1 NoSuchFieldError: LUCENE_6_0_0

流过昼夜 提交于 2019-12-10 17:13:03
问题 I am using elasticsearch 6.0.1 and on BulkRequest request = new BulkRequest(); I am getting the below error. I have checked online, mostly people said that this happens if I have different versions of lucene jars in the classpath. java.lang.NoSuchFieldError: LUCENE_6_0_0 at org.elasticsearch.Version.<clinit>(Version.java:44) at org.elasticsearch.common.logging.DeprecationLogger.<clinit>(DeprecationLogger.java:159) at org.elasticsearch.action.bulk.BulkRequest.<clinit>(BulkRequest.java:67) at

How Groovy script can be invoked using java api for Elasticsearch

懵懂的女人 提交于 2019-12-08 02:03:47
问题 Looking for pointers to know how Groovy script can be invoked using java api. test.groovy def value = dynamicValue return value Want to translate following query in Java: GET /test-index/_search { "query": { "match_all": {} }, "script_fields": { "checkValue": { "script": "test", "params": { "dynamicValue": 7 } } } } 回答1: You can do it like this: Map<String, Object> params = ImmutableMap.of("dynamicValue", 7); SearchResponse response = client().prepareSearch("test-index") .setQuery

How Groovy script can be invoked using java api for Elasticsearch

冷暖自知 提交于 2019-12-06 10:48:12
Looking for pointers to know how Groovy script can be invoked using java api. test.groovy def value = dynamicValue return value Want to translate following query in Java: GET /test-index/_search { "query": { "match_all": {} }, "script_fields": { "checkValue": { "script": "test", "params": { "dynamicValue": 7 } } } } Val You can do it like this: Map<String, Object> params = ImmutableMap.of("dynamicValue", 7); SearchResponse response = client().prepareSearch("test-index") .setQuery(matchAllQuery()) .addScriptField("checkValue", new Script("test", ScriptType.FILE, "groovy", params)) .execute()

How to do multiple filter query in Elasticsearch using Java?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 12:31:45
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. BoolQueryBuilder boolQuery = QueryBuilders.boolQuery() .must(QueryBuilders.simpleQueryStringQuery(query)

How to covert this elastic search functional score query to java API

一笑奈何 提交于 2019-12-02 01:30:46
How to convert the below ES query to Java API? I am using elastic search 2.3.3 GET /schema_name/_search { "from": 0, "size": 200, "query": { "function_score": { "query": { "match_all": {} }, "boost": "5", "functions": [{ "filter": { "term": { "alert_code": "event_rule_1" } }, "weight": 50 }, { "filter": { "term": { "alert_code": "event_rule_2" } }, "weight": 30 }, { "filter": { "term": { "alert_code": "event_rule_3" } }, "weight": 10 }, { "filter": { "term": { "alert_code": "event_rule_4" } }, "weight": 10 }, { "filter": { "term": { "alert_code": "event_rule_5" } }, "weight": 50 }, { "filter":