我可以从java代码的elasticsearch中获取记录,也可以使用elasticsearch _id来获取记录。为此,请使用以下Java代码。

    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    MatchQueryBuilder matchQueryBuilder = new MatchQueryBuilder("_id", id);
    searchSourceBuilder.query(matchQueryBuilder);
    searchRequest.source(searchSourceBuilder);

从Kibana,使用以下查询从elasticsearch获取记录,
GET /_search
{
    "query": {
        "query_string" : {
            "default_field" : "*",
            "query" : "M*"
        }
    }
}

现在,我想在Java中建立此查询。不知道如何在Java中建立此查询。

最佳答案

您可以这样做:

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
QueryStringQueryBuilder qsQueryBuilder = new QueryStringQueryBuilder("M*");
qsQueryBuilder.defaultField("*");
searchSourceBuilder.query(qsQueryBuilder);
searchRequest.source(searchSourceBuilder);

09-05 14:12