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
    }

  • 相关阅读:
    Linux-安装FFmpeg
    博客园添加视频
    博客园添加音乐
    通过容器提交镜像(docker commit)以及推送镜像(docker push)笔记
    根据不同配置.env获取不同的配置文件的配置
    1M大概多少个字
    计算机存储单位
    DNS原理及其解析过程
    查看到百度经过了多少个网关
    C语言的本质(18)——函数的可变参数
  • 原文地址:https://www.cnblogs.com/Robert-huge/p/13984235.html
Copyright © 2011-2022 走看看