美文网首页
ES查询示例

ES查询示例

作者: Shary王 | 来源:发表于2020-12-16 17:42 被阅读0次

1、查询值为空:

GET /indexName/_search

{"query":

      {

          "bool": {

            "should": [

              {

                "term": {

                  "pick_fbq_code": ""

                }

              },

              {

                "bool": {

                  "must_not": [

                    {

                      "exists": {

                        "field": "pick_fbq_code"

                      }

                    }

                  ]

                }

              }

            ]

          }

        }

}

GET /indexName/_search

{"query":

      {

          "bool": {

            "filter": {

              "prefix": {

                "pick_tm": "2019-09-29"

              }

            }

          }

        }

}

GET /indexName/_search

{"query":

      {

          "bool": {

            "filter": {

              "prefix": {

                "pick_tm": "2019-09-29"

              }

            },

                  "must_not": [

                    {

                      "exists": {

                        "field": "pick_fbq_code"

                      }

                    }

                  ]

          }

        }

}

GET /indexName/_search

{"query":

      {

          "bool": {

            "filter": {

                "term": {

                  "pick_fbq_code": ""

                }

            }  ,"must": [

              {

                "prefix": {

                "pick_tm": "2019-09-29"

              }

              }

            ] 

              }

        }

}

2、多条件查询Must

GET /risp_abc/_search

{"query":

      {

          "bool": {

          "must": [

            { "match": { "meterageWeightQty": ""}},

            { "match": { "consignedTime": "2019-09-30"}}

          ]

        }

    }

}

3、_delete_by_query条件删除

POST /indexName/typeName/_delete_by_query?conflicts=proceed&scroll_size=10000

{

  "query": {

    "range": {

      "receive_date": {

        "gte": "2019-10-01",

        "lte": "2019-10-01"

      }

    }

  }

}

4、查看模板

GET /*/_alias/indexName

GET /indexName/_alias/*

POST /_aliases

{

    "actions": [

        {

            "add": {

                "index": "indexName~20191029",

                "alias": "indexName"

            }

        }

        ]

}

5、新增字段

PUT my_index/_mapping/my_type

{

  "properties": {

    "new_column": {

      "type":    "integer"

    }

  }

}

6、

GET /indexName/_search

{

  "size": 0,

  "query": {

    "bool": {

      "must": [

        {"prefix": {

          "pickupDepotBatchDay": {

            "value": "laterIgnore_"

          }

        }}

      ]

    }},

    "aggregations" : {

    "pickupDay" : {

      "terms" : {

        "field" : "searchDay",

        "size" : 100000

      }}}

}

7、查询属性值长度不超过4的记录

GET /indexName/_search

{

"query": {

        "bool": {

            "must": {

                "script": {

                    "script": {

                        "inline": "doc['deliveryDeptCode'].length<4",

                        "lang": "painless"

                    }

                }

            }

        }

    }

}

8、shell脚本别名及异常捕捉

#!/bin/sh

es_host="http://10.110.106.47:9200/"

dt=$1

dt1=$2

dt2=$3

index="oewm_receive_dept_stats_day"

echo "$dt, $dt1, $dt2"

ret=0

result=1

errorStr='error":'

echo "errorStr= $errorStr"

result1=$(curl -XPOST "$es_host"_aliases -H 'Content-Type: application/json' -d'

{

    "actions": [

        {

            "add": {

                "index": "'${index}'~'${dt}'",

                "alias": "'${index}'"

            }

        }

    ]

}

')

if [[ $result1 =~ $errorStr ]]

then

  ret=1

  echo "result1= $result1"

fi

result2=$(curl -XPOST "$es_host"_aliases -H 'Content-Type: application/json' -d'

{

    "actions": [

        {

            "remove": {

                "index": "'${index}'~'${dt1}'",

                "alias": "'${index}'"

            }

        }

    ]

}

')

if [[ $result2 =~ $errorStr ]]

then

  ret=1

  echo "result2= $result2"

fi

result3=$(curl -XDELETE ${es_host}${index}~$dt2 && curl -XGET "$es_host"_alias/${index})

if [[ $result3 =~ $errorStr ]]

then

  ret=1

  echo "result3= $result3"

fi

echo "ret= $ret"

exit $ret

9、模糊查询排名

GET /indexName/_search

{

  "size": 0,

"query": {

    "bool": {

      "filter": [

        {

        "prefix": {

          "consignment": "托寄物"

        }

      },

      {

        "prefix": {

          "indexDay": "2020-09"

        }

      }

      ]

    }

} ,

    "aggregations" : {

    "deliveryCityCode" : {

      "terms" : {

        "field" : "deliveryCityCode",

        "size" : 100000

      }}}

}

10、模糊搜索

GET /indexName/_search

{

"query": {

  "wildcard": {

    "consignment": {

      "value": "*华为手机*"

    }}

}}

11、模糊搜索+多条件查询

GET indexName/_search

{

  "query":{

      "bool": {

      "filter": [

        {

          "term": {

            "processDate": {

              "value": "2020-12-16"

            }

          }

        },    { "query_string": {

        "default_field": "requireId",

        "query" : "*20121617568893*"

      }}

      ]

    }

  }

}

相关文章

  • ES查询示例

    1、查询值为空: GET /indexName/_search {"query": { "boo...

  • 利用掘金部分数据实现 Elasticsearch 示例项目

    爬取掘金的热门推荐页面部分信息作为示例数据保存到 es 中进行查询。 本项目中对 es 基本的创建、查询和删除操作...

  • scroll 方式查询es log 示例

    直接上code...

  • 2020-10-26-1-29即查即用

    示例1: 单列查询 示例2: 多列查询 示例3: 查询所有列 示例4: 起别名 示例05:对可能出现同列名的,起别...

  • ElasticSearch 7.x 聚合查询

    聚合查询 |ES 的聚合查询和MyQL的聚合查询类型,ES 的聚合查询相比MySQL 要强大的多,ES提供的统计数...

  • 流程控制 _ if 判断

    1,if 语法 2,if 使用 示例一 示例二 示例三_监控磁盘 示例四_查询端口状态 示例五_查询分数脚本

  • ES相关笔记

    常用操作 创建文档 检索文档 更多参考ES权威指南更多查询示例 删除文档 更新文档 更多脚本更新操作 并发更新控制...

  • Android SQLite 使用总结

    1.获取SQLiteOpenHelper 2.查询语句 查询多条数据 示例: 查询单条数据 示例: 模糊查询参考链...

  • mysql执行计划

    示例 字段说明 select_type 字段:查询的类型示例: SIMPLE:简单查询,不使用子查询、union。...

  • ES索引查询匹配,简单记录

    存入数据代码,以及es删除索引数据 从es里查询数据------单匹配查询

网友评论

      本文标题:ES查询示例

      本文链接:https://www.haomeiwen.com/subject/fakogktx.html