kibana查询

 

[06:55:25.594] [warning][reporting] Generating a random key for xpack.reporting.encryptionKey.
To prevent pending reports from failing on restart, please set xpack.reporting.encryptionKey in kibana.yml
根据提示,在配置文件kibana.yml中添加【xpack.reporting.encryptionKey】属性:
xpack.reporting.encryptionKey: "a_random_string"

[warning][security] Generating a random key for xpack.security.encryptionKey.
To prevent sessions from being invalidated on restart, please set xpack.security.encryptionKey in kibana.yml
根据提示,在配置文件kibana.yml中添加【xpack.security.encryptionKey】属性:
xpack.security.encryptionKey: "something_at_least_32_characters"

基本查询
PUT /mylib/person/1
{
  "name": "zhaosi",
  "address": "China ShangHaishi pudongxinqu",
  "age": "21",
  "interests": "like: play basket ball, travel, watch TV, games"
}

GET /mylib/person/1
{
  "_index" : "mylib",
  "_type" : "person",
  "_id" : "1",
  "_version" : 6,
  "_seq_no" : 5,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "name" : "zhaosi",
    "address" : "China ShangHaishi pudongxinqu",
    "age" : "21",
    "interests" : "like: play basket ball, travel, watch TV, games"
  }
}

查询喜欢旅游的人
GET /mylib/person/_search?q=interests:travel
{
  "took" : 1,    //花了1ms
  "timed_out" : false,  //是否超时
  "_shards" : {   //_shards指分片
    "total" : 5,  //搜索时从3个分片上搜索
    "successful" : 5, //3个分片上的搜索都成功了
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,  //查询出文档的个数
    "max_score" : 0.2876821, // 相关度分数,即搜索的匹配度
    "hits" : [
      {
        "_index" : "mylib",
        "_type" : "person",
        "_id" : "1",
        "_score" : 0.2876821,
        "_source" : {
          "name" : "zhaosi",
          "address" : "China ShangHaishi pudongxinqu",
          "age" : "21",
          "interests" : "like: play basket ball, travel, watch TV, games"
        }
      }
    ]
  }
}


term查询
GET /mylib/person/_search/
{
  "from": 0,  //从查询文档中第几个取
  "size": 2,  //取几个结果
  "query": {
    "terms": {
      "interests": [
        "basket ball",
        "travel"
      ]
    }
  }
}
查询结果:
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "mylib",
        "_type" : "person",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "name" : "zhaosi",
          "address" : "China ShangHaishi pudongxinqu",
          "age" : "21",
          "interests" : "like: play basket ball, travel, watch TV, games"
        }
      }
    ]
  }
}

match查询(会使用分词器)
GET /mylib/person/_search/
{
  "query": {
    "match": {
      "name": "zhaosi"
    }
  }
}
GET /mylib/person/_search/
{
  "query": {
    "match": {
      "name": "zhaosi zhaoming"
    }
  }
}
那么会把含有zhaosi或者zhaoming的都查出来
term不会分词只会查找叫"zhaosi zhaoming"的人
精确查找使用term,模糊查找使用match
GET /mylib/person/_search/
{
  "query": {
    "match": {
      "interests": "play basket ball, travel"
    }
  }
}
{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.1507283,
    "hits" : [
      {
        "_index" : "mylib",
        "_type" : "person",
        "_id" : "1",
        "_score" : 1.1507283,
        "_source" : {
          "name" : "zhaosi",
          "address" : "China ShangHaishi pudongxinqu",
          "age" : "21",
          "interests" : "like: play basket ball, travel, watch TV, games"
        }
      }
    ]
  }
}
multi_match 多个字段查询
GET /mylib/person/_search/
{
  "query": {
    "multi_match": {  #这里表示查询age或者interests中有21字符串的文档
      "query": "21", 
      "fields": ["age", "interests"]
    }
  }
}

match_phrase短语匹配
GET /mylib/person/_search/
{
  "query": {
    "match_phrase": {
       "interests": "play basket ball, travel" #必须和该字符串短语一模一样才行
    }
  }
}
includes用来指定查询的结果只显示哪些字段excludes用来指定查询的结果不显示哪些字段
GET /mylib/person/_search/
{
   "_source": {
     "includes": ["name", "addr*", "age"],  #*表示通配符
     "excludes": ["interests"]
   }
}

排序(需要安装Fielddata?)
GET /mylib/person/_search/
{
   "_source": {
     "includes": ["name", "addr*"],
     "excludes": ["interests"]
   },
   
    "sort": [
     {
       "age": {
         "order": "asc"
       }
     }
   ]
}

match_phrase_prefix
GET /mylib/person/_search/
{
  "query": {
    "match_phrase_prefix": {
      "name":{
         "query": "zhaos"
      }
    }
  } 
}
range范围查询
GET /mylib/person/_search/
{
  "query": {
    "range": {
      "age":{
          "from": 10,
          "to": 21,
          "include_lower": true,   //包含下界
          "include_upper": false   //不包含上界
      }
    }
  } 
}

wildcard查询(允许使用*?来匹配)
GET /mylib/person/_search/
{
  "query": {
    "wildcard": {
       "name": "zhao*"
    }
  } 
}

GET /mylib/person/_search/
{
  "query": {
    "wildcard": {
       "name": "zhao??"
    }
  } 
}

fuzzy模糊查询
GET /mylib/person/_search/
{
  "query": {
    "fuzzy": {
       "name": "zhaoki"  //能查到name为zhaosi的文档
    }
  } 
}
或者
GET /mylib/person/_search/
{
  "query": {
    "fuzzy": {
       "name": {
         "value": "zhaoki"
       }
    }
  } 
}
highlight高亮显示
GET /mylib/person/_search/
{
  "query": {
    "match": {
       "interests": "play basket ball"
    }
  } ,
  
  "highlight": {
       "fields": {
         "interests": {}
       }
  }
}

{
  "took" : 54,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 0.8630463,
    "hits" : [
      {
        "_index" : "mylib",
        "_type" : "person",
        "_id" : "1",
        "_score" : 0.8630463,
        "_source" : {
          "name" : "zhaosi",
          "address" : "China ShangHaishi pudongxinqu",
          "age" : "21",
          "interests" : "like: play basket ball, travel, watch TV, games"
        },
        "highlight" : {
          "interests" : [
            "like: <em>play</em> <em>basket</em> <em>ball</em>, travel, watch TV, games"
          ]
        }
      }
    ]
  }
}

 

PUT /sblj
{
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 1
  },
  
  "mappings": {
    "user":{
      "properties": {
        "name1":{"type":"text", "analyzer":"ik_max_word"},
        "address1":{"type":"text", "analyzer":"ik_max_word"},
        "age11":{"type":"integer"},
        "interests":{"type":"text", "analyzer":"ik_max_word"},
        "birthday1":{"type":"date"}
      }
    }
  }
}

{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "sblj"
}

GET /sblj/_mapping
{
  "sblj" : {
    "aliases" : { },
    "mappings" : {
      "user" : {
        "properties" : {
          "address1" : {
            "type" : "text",
            "analyzer" : "ik_max_word"
          },
          "age11" : {
            "type" : "integer"
          },
          "birthday1" : {
            "type" : "date"
          },
          "interests" : {
            "type" : "text",
            "analyzer" : "ik_max_word"
          },
          "name1" : {
            "type" : "text",
            "analyzer" : "ik_max_word"
          }
        }
      }
    },
    "settings" : {
      "index" : {
        "creation_date" : "1554258066694",
        "number_of_shards" : "3",
        "number_of_replicas" : "1",
        "uuid" : "XCrRsduqSA6E0xxBQ_3cBw",
        "version" : {
          "created" : "6070099"
        },
        "provided_name" : "sblj"
      }
    }
  }
}

 

posted @ 2019-04-02 17:41  牧 天  阅读(936)  评论(0)    收藏  举报