zoukankan      html  css  js  c++  java
  • term查询

    # term查询
    
    # term查询:查询某字段里有某个关键词的文档
    GET /library/books/_search
    {
      "query": {
        "term": {
            "preview": "elasticsearch"
        }
      }
    }
    
    {
      "took": 12,
      "timed_out": false,
      "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
      },
      "hits": {
        "total": 3,
        "max_score": 0.15372275,
        "hits": [
          {
            "_index": "library",
            "_type": "books",
            "_id": "2",
            "_score": 0.15372275,
            "_source": {
              "title": "The Elasticsearch cookbook",
              "price": 15,
              "preview": "One of the main requirements of today's applications is search capability. In the market, we can find a lot of solutions that answer this need, both in commercial as well as the open source world. One of the most used libraries for searching is Apache Lucene. This library is the base of a large number of search solutions such as Apache Solr, Indextank, and ElasticSearch.",
              "publish_date": "2015-05-12"
            }
          },
          {
            "_index": "library",
            "_type": "books",
            "_id": "1",
            "_score": 0.125,
            "_source": {
              "title": "Elasticsearch: The Definitive Guide",
              "price": 5,
              "preview": "Elasticsearch is a distributed, scalable, real-time search and analytics engine. It ena‐bles you to search, analyze, and explore your data, often in ways that you did not anticipate at the start of a project. It exists because raw data sitting on a hard drive is just not useful.",
              "publish_date": "2015-02-08"
            }
          },
          {
            "_index": "library",
            "_type": "books",
            "_id": "3",
            "_score": 0.033562027,
            "_source": {
              "title": "Elasticsearch Blueprints",
              "price": 9,
              "preview": "This book starts with the creation of a Google-like web search service, enabling you to generate your own search results. You will then learn how an e-commerce website can be built using Elasticsearch. We will discuss various approaches in getting relevant content up the results, such as relevancy based on how well a query matched the text, time-based recent documents, geographically nearer items, and other frequently used approaches.",
              "publish_date": "2015-06-01"
            }
          }
        ]
      }
    }
    
    [elk@node01 api]$ cat a11.pl 
    ##发送消息
    use  LWP::UserAgent; 
    use LWP;
    use Encode;
    use LWP::Simple;
    use LWP::UserAgent;
    use HTTP::Cookies;
    use HTTP::Headers;
    use HTTP::Response;
    use Encode;
    use URI::Escape;
    use URI::URL;
    use JSON;
    use Data::Dumper;
      my $ua = LWP::UserAgent->new;
         $ua->agent("Mozilla/5.0 (Windows NT 6.1; rv:30.0) Gecko/20100101 Firefox/30.0");
      my $cookie_jar = HTTP::Cookies->new(
         file=>'lwp_cookies.txt',
         autosave=>1,
         ignore_discard=>1);
         $ua->cookie_jar($cookie_jar);  
         my $login_url ="http://192.168.137.2:9200/library/books/_search";  
         my $post ={
         "query" => {
            "term" => {
            "preview" => "elasticsearch"
        }
      }
    };
        
        use JSON qw(encode_json);  
        $json_string = encode_json($post);  
      
        my $req = HTTP::Request->new(  
            'GET' => $login_url
        );  
        $req->content_type('application/json; charset=UTF-8')  
          ;    #post请求,如果有发送参数,必须要有这句  
        $req->content("$json_string");    #发送post的参数  
        my $res = $ua->request($req);  
        print $res->content()."
    ";            #获取的是响应正文  
    [elk@node01 api]$ perl a11.pl 
    {"took":1,"timed_out":false,
    "_shards":{"total":5,"successful":5,"failed":0},
    "hits":{"total":3,"max_score":0.15372275,
    "hits":[{"_index":"library","_type":"books","_id":"2","_score":0.15372275,
    "_source":{ "title":"The Elasticsearch cookbook","price":15,"preview":"One of the main requirements of today's applications is search capability. In the market, we can find a lot of solutions that answer this need, both in commercial as well as the open source world. One of the most used libraries for searching is Apache Lucene. This library is the base of a large number of search solutions such as Apache Solr, Indextank, and ElasticSearch.", "publish_date":"2015-05-12" }},
    {"_index":"library","_type":"books","_id":"1","_score":0.125,"_source":{ "title":"Elasticsearch: The Definitive Guide","price":5,"preview":"Elasticsearch is a distributed, scalable, real-time search and analytics engine. It ena‐bles you to search, analyze, and explore your data, often in ways that you did not anticipate at the start of a project. It exists because raw data sitting on a hard drive is just not useful." ,"publish_date":"2015-02-08"}},
    {"_index":"library","_type":"books","_id":"3","_score":0.033562027,"_source":{ "title":"Elasticsearch Blueprints","price":9,"preview":"This book starts with the creation of a Google-like web search service, enabling you to generate your own search results. You will then learn how an e-commerce website can be built using Elasticsearch. We will discuss various approaches in getting relevant content up the results, such as relevancy based on how well a query matched the text, time-based recent documents, geographically nearer items, and other frequently used approaches." , "publish_date":"2015-06-01"}}]}}

  • 相关阅读:
    ACR2010_TNF拮抗剂促进SpA患者椎体侵蚀的修复
    2010年10月第1期(ACR2010专刊AS篇)_中信国健临床通讯目录
    ACR2010_中轴型SpA患者使用TNF拮抗剂治疗后放射学进展与全身炎症消退相关
    ACR2010_小剂量依那西普对达到缓解的AS患者有效
    ACR2010_在高风险人群中应用新版RA分类标准可能发现更多临床前RA
    ACR2010_常规医疗环境下TNF拮抗剂对RA骨侵蚀的修复作用
    ACR2010_HLA B27阳性的极早期AS患者停用TNF拮抗剂后疗效持续: 3个月随机安慰剂对照试验后随访40周
    .net委托与事件 中庸
    筛选法因子之和
    POJ2488 A Knight's Journey 解题报告
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349686.html
Copyright © 2011-2022 走看看