es查询和更新 语句示例
文档目录: https://www.elastic.co/guide/index.html
GET _search
{
"query": {
"match_all": {}
}
} GET /_template/* PUT /_template/hs_server_template
{
"order": 0,
"version": 60001,
"index_patterns": [
"hs_server*"
],
"settings": {
"index": {
"refresh_interval": "5s"
}
},
"mappings": {
"doc": {
"dynamic_templates": [
{
"message_field": {
"path_match": "message",
"match_mapping_type": "string",
"mapping": {
"type": "text",
"norms": false
}
}
},
{
"string_fields": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"type": "text",
"norms": false,
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
],
"properties": {
"@timestamp": {
"type": "date"
},
"@version": {
"type": "keyword"
},
"ErrorCode": {
"type": "integer"
},
"geoip": {
"dynamic": true,
"properties": {
"ip": {
"type": "ip",
"latitude": {
"type": "half_float"
},
"longitude": {
"type": "half_float"
}
}
},
"responseLogTime": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss.SSS||yyyy-MM-dd||epoch_millis||yyyy-MM-dd HH:mm:ss.SSSZ"
}
}
}
},
"aliases": {}
}
} DELETE /_template/my_test_play_dur_template PUT /_template/tv_stats_play_dur_template
{
"order": 0,
"version": 60001,
"index_patterns": [
"tv_stats_play_dur*"
],
"settings": {
"index": {
"refresh_interval": "30s"
}
},
"mappings": {
"doc": {
"dynamic_templates": [
{
"message_field": {
"path_match": "message",
"match_mapping_type": "string",
"mapping": {
"type": "text",
"norms": false
}
}
},
{
"string_fields": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"type": "text",
"norms": false,
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
],
"properties": {
"@timestamp": {
"type": "date"
},
"@version": {
"type": "keyword"
},
"remote_address": {
"type": "ip"
},
"duration": {
"type": "long"
},
"id": {
"type": "long"
},
"importbatchno": {
"type": "keyword"
},
"index_name_suffix": {
"type": "keyword"
},
"mac": {
"type": "keyword"
},
"main_id": {
"type": "long"
},
"main_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"sub_id": {
"type": "long"
},
"sub_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"type_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"url": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"userid": {
"type": "long"
},
"versioncode": {
"type": "keyword",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
},
"aliases": {}
} GET /tv_stats_play_dur-2019-06-05/_search/
DELETE /my_test-2019.05.10
GET /my_test-2019.05.13/_search #query
GET /tv_stats_play_dur*/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"root_id": 5
}
},
{
"match": {
"sub_id": 0
}
}
],
"must_not": [
{ "match": { "root_name": "直播" } }
]
}
}
} #batch update or bulk update
POST /tv_stats_play_dur*/doc/_update_by_query?conflicts=proceed
{
"query": {
"bool": {
"must": [
{
"term": {
"root_id": 5
}
},
{
"match": {
"sub_id": 0
}
}
],
"must_not": [
{
"match": {
"root_name": "直播"
}
}
]
}
},
"script": {
"lang": "painless",
"source": "ctx._source.root_name = params.live_name",
"params": {
"live_name": "直播"
}
}
} # get count num of null root by root,main,sub
GET /tv_stats_play_dur-2019-06-07*/_search?search_type=dfs_query_then_fetch
{
"query": {
"bool": {
"must_not": [
{
"exists": {
"field": "root_name.keyword"
}
}
]
}
},
"aggs": {
"root_id": {
"terms": {
"field": "root_id",
"size": 25
},
"aggs": {
"main_id": {
"terms": {
"field": "main_id",
"size": 25
},
"aggs": {
"sub_id": {
"terms": {
"field": "sub_id",
"size": 25
}
}
}
}
}
}
}
} #root name null group by date
GET /tv_stats_play_dur-2019-06*/_search?search_type=dfs_query_then_fetch
{
"query": {
"bool": {
"must_not": [
{
"exists": {
"field": "root_name.keyword"
}
}
]
}
},
"aggs": {
"root_id": {
"terms": {
"field": "importbatchno",
"size": 25
}
}
}
} #search by import date
GET /tv_stats_play_dur*/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"importbatchno": 20190610
}
}
]
}
}
} #delete by import date
POST /tv_stats_play_dur*/doc/_delete_by_query
{
"query": {
"bool": {
"must": [
{
"term": {
"importbatchno": 201906101
}
}
]
}
}
} ##########################
GET /hs_server_ahc_task*/_search
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"match": {
"LogMessage": "Error"
}
},
{
"match": {
"LogMessage": "MessagePull"
}
}
]
}
}
]
}
}
}
es同个字段,多个值搜索的案例
search_pdf_query = {"query": {
"bool":
{
"must": [
{"bool": {"should":[{"match_phrase": {"pdf_title":"年度报告"}},{"match_phrase":{"pdf_title":"季度报告"}}]}},
{"range": {"announce_date": {"gte": "2017-01-01","lte": "2018-12-31"}}},
{"terms": {"html_status": ["201", "300", "301", "302"]}},
{"terms": {"trade_code.keyword": ["600548","000548"]}}],
"must_not": [{"wildcard": {"origin_title.keyword": '*摘要'}},{"wildcard": {"origin_title.keyword": '*年度报告书'}}],
}},
"sort": [{"announce_date": "asc"}]
}
查找值包含某些文本的情况:
- 完全匹配情况下,对同一个字段的多个值搜索,使用terms查询,举例:
{"terms": {"html_status": ["201", "300", "301", "302"]}}
- 如果不完全匹配,则在must里添加bool查询,再在bool里添加should查询,举例:
{"bool": {"should":[{"match_phrase": {"pdf_title":"年度报告"}},{"match_phrase":{"pdf_title":"季度报告"}}]}}
如何区分使用match,match_phrase,term可参考此篇
https://blog.csdn.net/camelcanoe/article/details/79544155
这里也涉及到查询的字段是否是 NOT_ANALYZED,ANALYZED字段无法使用term,只能使用match_phrase。
所以在新建index的时候需要把mapping设置好,哪些字段是ANALYZED,哪些是NOT_ANALYZED(感觉是个坑)
es查询和更新 语句示例的更多相关文章
- es 查询更新操作
# es 查询更新操作# _*_ coding: utf-8 _*_ import time import datetime import pymysql from elasticsearch imp ...
- sql查询语句示例
今天没事又专门学习了一下sql查询语句,个人感觉太重要了,于是就找了网上的一个示例自己练了起来,感觉学到了很多,下面跟大家分享一下sql查询语句的示例操作. 首先,我建了5张表,分别如下: (a)学生 ...
- Hudi 数据湖的插入,更新,查询,分析操作示例
Hudi 数据湖的插入,更新,查询,分析操作示例 作者:Grey 原文地址: 博客园:Hudi 数据湖的插入,更新,查询,分析操作示例 CSDN:Hudi 数据湖的插入,更新,查询,分析操作示例 前置 ...
- ES查询语句
记录常用的es 查询 聚合 GET _cat / indices GET / p_ext_develop / _mapping / g GET / p_ext_develop / _analyze { ...
- Es查询结果集默认是10000,更新设置
Es查询结果集默认是10000,结果集大小是int,最大为21亿左右 PUT _all/_settings?preserve_existing=true { "index.max_resul ...
- 使用TSQL查询和更新 JSON 数据
JSON是一个非常流行的,用于数据交换的文本数据(textual data)格式,主要用于Web和移动应用程序中.JSON 使用“键/值对”(Key:Value pair)存储数据,能够表示嵌套键值对 ...
- Microsoft SQL - 查询与更新
查询与更新(Query & Update) 转义引号 SQL语句中字符串只能使用单引号,如果需要转义,可用单引号转义单引号. 查询(Inquire) 以下公式中的c指代列名. 规则 1.查询语 ...
- Mysql语句示例
Mysql语句示例 最常用 sql 语句总结 前言 Mysql 是数据库开发使用的主要平台之一.sql 的学习掌握与使用是数据库开发的基础,此处展示详细sql 语句的写法,及各种功能下的 sql 语句 ...
- AppBox升级进行时 - 关联表查询与更新(Entity Framework)
AppBox 是基于 FineUI 的通用权限管理框架,包括用户管理.职称管理.部门管理.角色管理.角色权限管理等模块. 关联表的查询操作 使用 Include 方法,我们可以在一次数据库查询中将关联 ...
随机推荐
- git 学习笔记 —— 获取远端分支并修改后提交至远端仓库
笔者最近进行开发过程中,所有参与者的代码需要通过 git 上传到远端仓库中,不同的模块对应不同的 git 分支,不同模块的数据需要从远端仓库中获取.这里记录下笔者从远端仓库中获取分支数据,进行修改,最 ...
- 13、Python文件处理、os模块、json/pickle序列化模块
一.字符编码 Python3中字符串默认为Unicode编码. str类型的数据可以编码成其他字符编码的格式,编码的结果为bytes类型. # coding:gbk x = '上' # 当程序执行时, ...
- wordpress数字分页列表导航实现
前面我们用了自定义的方式来实现wordpress数字分页,其实wordpress是已经有集成了Numbered Pagination相关的函数,我们直接调用就可以.具体实现方法如下代码调用 <? ...
- React Hook Flow Diagram
一.概述 Donovon has created this nice flowchart that explains the new lifecycle of a Hooks component. C ...
- SG函数的理解集应用
转载自知乎牛客竞赛——博弈论入门(函数讲解+真题模板) SG函数 作用 对于一个状态i为先手必胜态当且仅当SG(i)!=0. 转移 那怎么得到SG函数尼. SG(i)=mex(SG(j))(状态i可以 ...
- QQ互联登陆(Java)
一.准备部分 1.账户注册 腾讯开放平台网址: https://connect.qq.com/index.html 首先需要到开放平台注册QQ互联开发者身份.注册之后创建一个网站应用,注意,需要备案成 ...
- yolov3
YOLOv3没有太多的创新,主要是借鉴一些好的方案融合到YOLO里面.不过效果还是不错的,在保持速度优势的前提下,提升了预测精度,尤其是加强了对小物体的识别能力(yolov1在这方面是有缺陷的). 本 ...
- 使用plotly dash-component-boilerplate 生成自己的组件
plotly 基于dash-component-boilerplate给我们提供了可以快速生成基于使用python 调用的react 组件 以下是一个简单的使用脚手架生成一个组件,同时可以了解组件的工 ...
- Android 系统Action大全
常用Action说明: String ADD_SHORTCUT_ACTION 动作:在系统中添加一个快捷方式.. “android.intent.action.ADD_SHORTCUT” String ...
- x64下进程保护HOOK
目录 x64(32)下的进程保护回调. 一丶进程保护线程保护 1.简介以及原理 1.2 代码 1.3注意的问题 二丶丶回调函数写法 2.1 遇到的问题. 2.2 回调代码 x64(32)下的进程保护回 ...