ElasticSearch in 语句

SQL语句示例

select * from table where t_id in (1,2,3,4)

对应es原生查询语句

GET /index/type/_search
{
  "query": {
    "terms": {
      "t_id": [1,2,3,4]
    }
  }
}

Java API,注意是term[s]Query,不是termQuery

SearchRequestBuilder searchRequestBuilder =
                client.prepareSearch(index).setTypes(type).setSearchType(SearchType.QUERY_THEN_FETCH);
...
searchRequestBuilder.setQuery(QueryBuilders.termsQuery("t_id", idList));

 

你可能感兴趣的:(ES,ElasticSearch)