2024年4月28日发(作者:)

然后查询tweets索引tweet类型中,user字段的值包含在users索引user类型的数组中

GET /tweets/_search

{

"query" : {

"terms" : {

"user" : {

"index" : "users",

"type" : "user",

"id" : "2",

"path" : "followers"

}

}

}

}

结果:

{

"took": 2,

"timed_out": false,

"_shards": {

"total": 5,

"successful": 5,

"failed": 0

},

"hits": {

"total": 1,

"max_score": 0.2876821,

"hits": [

{

"_index": "tweets",

"_type": "tweet",

"_id": "1",

"_score": 0.2876821,

"_source": {

"user": "1"

}

}

]

}

}

可以通过Java 发送http请求去查询。

import st;

import tType;

import gEntity;

import Utils;

import se;

import ient;

import tions;

public class JavaTermsHttp {

public static void main(String[] args) throws Exception {

RestClient restClient = r(

new HttpHost("192.168.7.61", 9200, "http")).build();

Response response = mRequest("POST", "/tweets/_search", Collections.emptyMap(),

new NStringEntity("{n" +

" "query" : {n" +

" "terms" : {n" +

" "user" : {n" +

" "index" : "users",n" +

" "type" : "user",n" +

" "id" : "2",n" +

" "path" : "followers"n" +

" }n" +

" }n" +

" }n" +

"}", ATION_JSON));

n(ng(ity()));

();

}

}