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"}}]}}

  • 相关阅读:
    资源链接 标签: 笔记 2016-08-15 13:51 66人阅读 评论(0) 收藏
    js函数 标签: javascript 2016-08-12 16:48 56人阅读 评论(0) 收藏
    js数组 标签: javascript 2016-08-03 14:15 131人阅读 评论(0) 收藏
    typeof操作符和instanceof操作符的区别 标签: JavaScript 2016-08-01 14:21 113人阅读 评论(
    js笔记 标签: javascript 2016-08-01 13:30 75人阅读 评论(0) 收藏
    Linux命令 标签: linux 2016-08-01 10:26 508人阅读 评论(0) 收藏
    linux 用户切换 标签: linux 2016-07-30 13:57 144人阅读 评论(0) 收藏
    高质量C++C编程指南笔记 标签: c++笔记 2015-11-22 20:59 179人阅读 评论(0) 收藏
    CSS学习笔记
    C++ Primer Plus(6th Edition) 习题总结(2)
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349686.html
Copyright © 2011-2022 走看看