我用“curl”和“Java Client”执行了“elasticsearch”。
结果不同。
这些是不同的
我想修复Java客户端代码。 请告诉我如何修复Java客户端。
curl -XGET http://localhost:9200/_search?pretty -d '
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"match": {
"test1": "java"
}
}
]
}
},
{
"bool": {
"must": [
{
"match": {
"test2": "java"
}
}
],
"boost" : 5.0
}
}
]
}
}
}
'
{
"took" : 13,
"timed_out" : false,
"_shards" : {
"total" : 100,
"successful" : 100,
"failed" : 0
},
"hits" : {
"total" : 172405,
"max_score" : 16.018892,
"hits" : [
{
"_index" : "member",
"_type" : "type",
"_id" : "2",
"_score" : 16.018892,
"_source" : {
"fw" : [
"java"
]
}
}
]
}
}
private String hostnames = "hostname:9300";
private String clusterName = "clustername";
Settings settings = Settings.builder()
.put("cluster.name", clusterName)
.build();
TransportClient client = new PreBuiltTransportClient(settings);
for (String hosname : hostnames.split(",")) {
HostAndPort hp = HostAndPort.fromString(hosname);
String hostName = hp.getHostText();
int port = hp.getPort();
try {
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostName),port));
} catch (UnknownHostException e) {
client.close();
throw new RuntimeException("hostname is injustice");
}
}
BoolQueryBuilder shouldQuery = QueryBuilders.boolQuery();
BoolQueryBuilder boolQueryTest1 = QueryBuilders.boolQuery();
BoolQueryBuilder boolQueryTest2 = QueryBuilders.boolQuery();
boolQueryTest1.must(QueryBuilders.matchQuery("test1", "java"));
boolQueryTest2.must(QueryBuilders.matchQuery("test2", "java").boost((float) 5.0));
shouldQuery.should(boolQueryTest1);
shouldQuery.should(boolQueryTest2);
SearchResponse response = client.prepareSearch()
.setQuery(shouldQuery)
.execute()
{
"took": 7,
"timed_out": false,
"_shards": {
"total": 100,
"successful": 100,
"failed": 0
},
"hits": {
"total": 172449,
"max_score": 19.487148,
"hits": [
{
"_index": "blog",
"_type": "type",
"_id": "3",
"_score": 19.487148,
"_source": {
"fw": [
"java"
]
}
}
]
}
}