hello
I'm starting with elasticsearch, and use the instructions on how to access and create a java client. Marvel made a consultation with the next code:
GET consolidacion/store/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"data.package_field": "0.D.42.17"
}
}
]
}
}
}
and I get
{
"took": 8,
"timed_out": false,
"_shards": {
"total": 10,
"successful": 10,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 9.14017,
"hits": [
{
"_index": "consolidacion",
"_type": "store",
"_id": "ee24f357c51456ebb84be4897c128bc4",
"_score": 9.14017,
"_source": {
"transaction_uuid": "33fdfa63-f4be-8a27-52f5-d247871a4d71",
"order": 7,
"hash": "ee24f357c51456ebb84be4897c128bc4",
"application_uuid": "477e9531-0a22-4da2-8777-27c7be176ebc",
"repository_uuid": "275f7132-d82f-11e4-8188-000c29cd",
"user": null,
"data": {
"package_field": "0.D.42.17",
"package": "0.D.42",
"nro_registro": 0,
"value": "BERTULFO",
"package_field_key": "0.D.42.26",
"package_field_key_value": "415400"
},
"log_date": "2015-06-30T16:27:09-05:00",
"organization_uuid": "bb0561c3-d911-11e4-8188-000c29cd54dc",
"provider": "191100000501",
"person_identifiers": [
{
"identifier": "bec8ea50-1f6e-11e5-9254-000c29ea4ee7",
"domain_name": "ECID"
},
{
"identifier": "415400",
"domain_name": "CODPERSON:275f7132-d82f-11e4-8188-000c29cd"
}
]
}
}
]
}
}
Java I have the following.
Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "sitis").put("node.name", "sitis-n1").build();
Client esclient = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress("172.16.1.202", 9300));
We perform validation checking index, and passes without problem.
final IndicesExistsResponse res = esclient.admin().indices().prepareExists(indexName).execute().actionGet();
Then I pass the query, and see if I return the ID, but does not give me fields and I do not understand why it happens this
way.
String keyField="data.package_field";
String keyValue="0.D.42.17";
String queryString="{\"query\": {\"bool\": {\"must\": [ {\"match\": {\""+keyField+"\": \""+keyValue+"\" } } ] } } }";
//Sample Query - JSONObject
//We convert the raw query string to JSONObject to avoid query parser error in Elasticsearch
JSONObject queryStringObject = new JSONObject(queryString);
//Elasticsearch Response
SearchResponse response = esclient.prepareSearch(indexName).setTypes(typeName).setSource(queryStringObject.toString()).execute().actionGet();
//Elasticsearch Response Hits
SearchHits hits = response.getHits();
This pom dependencies
<dependencies>
<!-- add the Shield jar as a dependency -->
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch-shield</artifactId>
<version>1.3.0</version>
</dependency>
<!-- add the License jar as a dependency -->
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch-license-plugin</artifactId>
<version>1.0.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
</dependencies>
<repositories>
<!-- add the elasticsearch repo -->
<repository>
<id>elasticsearch-releases</id>
<url>http://maven.elasticsearch.org/releases</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
Any idea? and thanks for your valuable collaboration.