In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the "local implementation of es query" related knowledge, in the actual case operation process, many people will encounter such a dilemma, and then let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!
Import cn.jpush.statistics.elasticsearch.ReportDO;import cn.jpush.statistics.util.JsonUtil;import com.google.common.collect.Lists;import lombok.extern.slf4j.Slf4j;import org.elasticsearch.action.get.GetResponse;import org.elasticsearch.action.search.SearchRequestBuilder;import org.elasticsearch.action.search.SearchResponse;import org.elasticsearch.client.transport.TransportClient;import org.elasticsearch.common.settings.Settings;import org.elasticsearch.common.transport.TransportAddress;import org.elasticsearch.index.query.*;import org.elasticsearch.search.SearchHit Import org.elasticsearch.transport.client.PreBuiltTransportClient;import org.joda.time.DateTime;import org.joda.time.DateTimeFieldType;import org.joda.time.LocalDate;import java.net.InetAddress;import java.net.UnknownHostException;import java.util.ArrayList;import java.util.Date;import java.util.List;import static org.elasticsearch.index.query.QueryBuilders.matchQuery;@Slf4jpublic class EsClient {public static void main (String [] args) throws UnknownHostException {esSearch () } private static void esSearch () throws UnknownHostException {/ / specify the cluster Settings settings = Settings.builder () .put ("cluster.name", "elasticsearch") .put ("client.transport.sniff", false) .build (); / / create a client TransportClient client = new PreBuiltTransportClient (settings) .addTransportAddress (new TransportAddress (InetAddress.getByName ("127.0.0.1"), 9300) that accesses es / / TermQueryBuilder query = QueryBuilders.termQuery ("channel", "GDT"); BoolQueryBuilder query = QueryBuilders.boolQuery (); List must = query.must (); must.add ("channel", "GDT" .toLowerCase ()); DateTime start = new DateTime (2017); DateTime end = new DateTime (2020) Must.add (QueryBuilders.termQuery ("advertiser_id", 12)); must.add (QueryBuilders.termQuery ("product_id", 98)); RangeQueryBuilder rangeQueryBuilder = QueryBuilders .rangeQuery ("query_time") .gt (start.getMillis ()) .lte (end.getMillis ()) .format ("epoch_millis") Must.add (rangeQueryBuilder); / / must.add (QueryBuilders.termsQuery ("advertiser_id", Lists.newArrayList (2443)); SearchRequestBuilder builder = client.prepareSearch ("ad-report-v3-20 *") .setTypes ("report") .setQuery (query); log.info ("elastic.list.query.string:\ n\ n {}\ n\ n", builder.toString ()) SearchResponse response = builder// .setSize (3) .get (); for (SearchHit hit: response.getHits ()) {String sourceAsString = hit.getSourceAsString (); ReportDO reportDO = JsonUtil.parseObject (sourceAsString, ReportDO.class); System.out.println (JsonUtil.toJsonString (reportDO));} client.close () }} this is the end of the content of "locally implemented es query". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.