zoukankan      html  css  js  c++  java
  • ELK之复杂查询和高亮查询


    DELETE cyyindex
    PUT cyyindex
    {
    "mappings": {
    "properties": {
    "name": {
    "type": "keyword"
    },
    "address": {
    "type": "text"
    },
    "age": {
    "type": "integer"
    }
    }
    }
    }

    GET /cyyindex
    GET /cyyindex/_doc/_search

    GET cyyindex/_doc/_search?q=name:"孙权"
    GET cyyindex/_doc/_search?q=address:魏

    GET cyyindex/_doc/_search
    {
    "query":{
    "match":{
    "name":"曹操"
    }
    }
    }

    GET cyyindex/_doc/_search
    {
    "query":{
    "match":{
    "address":"魏"
    }
    }
    }

    GET cyyindex/_doc/_search
    {
    "query":{
    "match":{
    "address":"魏"
    }
    },
    "_source":["name","address","age"]
    }

    # 排序
    GET cyyindex/_doc/_search
    {
    "query":{
    "match":{
    "address":"魏"
    }
    },
    "_source":["name","address","age"],
    "sort":[
    {"age":{"order":"asc"}},
    {"name":{"order":"asc"}}
    ]
    }

    # 分页查询
    GET cyyindex/_doc/_search
    {
    "query":{
    "match":{
    "address":"魏国"
    }
    },
    "_source":["name","address","age"],
    "sort":[
    {"age":{"order":"desc"}},
    {"name":{"order":"asc"}}
    ],
    "from":0,
    "size":2
    }

    # where条件查询
    # And
    GET cyyindex/_doc/_search
    {
    "query":{
    "bool":{
    "must":[
    {
    "match":{
    "address":"魏国"
    }
    },
    {
    "match":{
    "name":"贾诩"
    }
    }
    ]
    }
    },
    "_source":["name","address","age"],
    "sort":[
    {"age":{"order":"desc"}},
    {"name":{"order":"asc"}}
    ],
    "from":0,
    "size":10
    }

    # OR
    GET cyyindex/_doc/_search
    {
    "query":{
    "bool":{
    "should":[
    {
    "match":{
    "address":"魏国"
    }
    },
    {
    "match":{
    "name":"贾诩"
    }
    }
    ]
    }
    },
    "_source":["name","address","age"],
    "sort":[
    {"age":{"order":"desc"}},
    {"name":{"order":"asc"}}
    ],
    "from":0,
    "size":10
    }

    # NOT查询
    GET cyyindex/_doc/_search
    {
    "query":{
    "bool":{
    "must_not":[
    {
    "match":{
    "name":"曹操"
    }
    }
    ],
    "filter":{
    "range":{
    "age":{
    "gte":19,
    "lte":29
    }
    }
    }
    }
    },
    "_source":["name","address","age"],
    "sort":[
    {"age":{"order":"desc"}},
    {"name":{"order":"asc"}}
    ],
    "from":0,
    "size":10
    }

    # 高亮查询
    GET cyyindex/_doc/_search
    {
    "query":{
    "match":{"name":"曹操"}
    },
    "highlight":{

    "fields": {
    "name": {}
    }
    }
    }


    # 自定义高亮查询
    GET cyyindex/_doc/_search
    {
    "query":{
    "match":{"name":"曹操"}
    },
    "highlight":{

    "pre_tags":"<p class='gaoliang'>",
    "post_tags":"</p>",
    "fields": {
    "name": {}
    }
    }
    }

    # 插入数据
    POST /cyyindex/_doc
    {
    "name":"曹操",
    "address":"魏国",
    "age":18
    }

    POST /cyyindex/_doc
    {
    "name":"贾诩",
    "address":"魏国",
    "age":19
    }

    POST /cyyindex/_doc
    {
    "name":"诸葛亮",
    "address":"蜀国",
    "age":18
    }

    POST /cyyindex/_doc
    {
    "name":"魏延",
    "address":"蜀国",
    "age":18
    }

    POST /cyyindex/_doc
    {
    "name":"关羽",
    "address":"蜀国",
    "age":18
    }

    POST /cyyindex/_doc
    {
    "name":"周瑜",
    "address":"吴国",
    "age":18
    }

    POST /cyyindex/_doc
    {
    "name":"孙权",
    "address":"吴国",
    "age":18
    }

  • 相关阅读:
    uwsgi配置
    sed_shell三剑客
    grep_shell三剑客
    awk_shell三剑客
    spring(二)
    spring(一)
    5G的科普
    应用层协议基础
    IP地址相关运算(如VLSM,超网汇总)
    ARP协议基础
  • 原文地址:https://www.cnblogs.com/Robert-huge/p/13984235.html
Copyright © 2011-2022 走看看