当前位置:网站首页>Es common curl finishing
Es common curl finishing
2022-06-30 10:20:00 【Fallacious】
Server es Simple addition, deletion, modification and query still prefer to send directly curl, So simply sort it out
Often tread on small pits
1、url There are characters to escape in the
If url Medium id There are special characters in , Need to escape , Such as #, Need to change to %23, if id by wangergou#24, be url Should be converted to
http://127.0.0.1:9200/user/user/wangergou%2324
2、curl Of body Partial quotation marks
Note the single and double quotation marks , Double quotation marks inside single quotation marks do not need to be escaped , The double quotation marks inside the double quotation marks need to be escaped
-d "{
\"query\": {
\"term\": {
\"name\": \"zhangsan\"}}}"
perhaps
-d '{"query": {"term": {"name": "zhangsan"}}}'
One 、 Inquire about
1、 View all indexes
# v Show details ,pretty With json Form show
curl -i -XGET http://localhost:9200/_cat/indices?v
curl -i -XGET http://localhost:9200/_cat/indices?pretty
2、 Query the specified document
# Inquire about user The index contains zhang Documents ( Fuzzy )
curl -i -XGET http://localhost:9200/user/_search?q=zhang
# Inquire about user The index contains name yes zhangsan Documents ( accurate )
curl -X POST http://localhost:9200/user/_search -d "{
\"query\": {
\"term\": {
\"name\": \"zhangsan\"}}}" --header "Content-Type: application/json"
Less commonly used complex queries are left behind
3、 View multiple records
# By default, only return 10 strip , Add parameters to view 1-50 strip
curl -XPOST http://localhost:9200/user/_search?pretty -d "{
\"from\": 0, \"size\": 50,\"query\":{
\"match_all\":{}}}" --header "Content-Type: application/json"
Two 、 increase
1、 Add index
curl -XPUT 'http://192.168.80.200:9200/address
2、 Add a record
# towards user Add an entry to the index id by wangergou The record of
curl -X PUT http://127.0.0.1:9200/user/user/wangergou -d'{"name":"wangergou","age":24}' --header "Content-Type: application/json"
3、 ... and 、 Delete
1、 Delete index
# Delete index user
curl -i -XDELETE http://127.0.0.1:9200/user
# Delete multiple indexes
curl -i -XDELETE http://127.0.0.1:9200/user,history
# Wildcard delete index
curl -i -XDELETE http://localhost:9200/test*
# Delete all indexes
curl -i -XDELETE http://127.0.0.1:9200/_all
2、 Delete the specified record
# Delete user Index name yes zhangsan The record of
curl -X POST http://127.0.0.1:9200/user/user/_delete_by_query -d'{"query":{"match":{"name" :"zhanagsan"}}}' --header "Content-Type: application/json"
Four 、 to update
1、 Update the specified document
# Update the... Of the specified document zhangsan Of age Field is 26
curl -XPOST http://127.0.0.1:9200/user/user/zhangsan/_update -d '{"doc" : {"age":26}}' --header "Content-Type: application/json"
5、 ... and 、 View the cluster status
1、 View cluster health status
curl -i -XGET http://localhost:9200/_cat/health?v
2、 Query cluster statistics
curl -i -XGET http:/localhost:9200/_cluster/stats
6、 ... and 、 Complex queries
1、 Fuzzy query
The following is curl Of body part
# all firstname Field is Virginia perhaps Ayala All documents of
{
"query": {
"match": {
# General search
"firstname": {
"query": "virginia jones", # Search keywords
"operator": "or" # operation : or and
}
}
}
}
# all address Field inclusion Virginia Ayala All documents of
{
"query": {
"match_phrase": {
# Phrase search
"address": "Baycliff Terrace"
}
}
}
# Field address,firstanme,lastname contains Baycliff perhaps Terrace All documents of
{
"query": {
"multi_match": {
# Multi field phrase search
"query": "Baycliff Terrace",
"fields": ["address", "firstname", "lastname"]
}
}
}
match When matching, word segmentation will be performed on the searched keywords , Then press word segmentation to find , and term Will directly search for keywords . Generally, when fuzzy search , multi-purpose match, For exact search, you can use term
2、 Precise query
{
'query':{
'terms':{
'tag':["search",'nosql','hello']
}
}
}
3、bool Inquire about
bool The query contains four clauses ,must,filter,should,must_not
{
'query':{
'bool':{
'must':[{
'term':{
'_type':{
'value':'age'
}
}
},{
'term':{
'account_grade':{
'value':'23'
}
}
}
]
}
}
}
{
"bool":{
"must":{
"term":{
"user":"lucy"}
},
"filter":{
"term":{
"tag":"teach"}
},
"should":[
{
"term":{
"tag":"wow"}},
{
"term":{
"tag":"elasticsearch"}}
],
"mininum_should_match":1,
"boost":1.0
}
}
4、filter Inquire about
query and filter The difference between :query When querying , Will first compare the query conditions , And then calculate the score , Finally, the document result is returned ; and filter First, judge whether the query conditions are met , If not, the query results will be cached ( Record that the document does not satisfy the result ), If you are satisfied , Just cache the results directly
filter Come on : Caching results , Avoid calculating points
{
"query": {
"bool": {
"must": [
{
"match_all": {
}}
],
"filter": {
"range": {
"create_admin_id": {
"gte": 10,
"lte": 20
}
}
}
}
}
}
5、range Inquire about
{
'query':{
'range':{
'age':{
'gte':'30',
'lte':'20'
}
}
}
}
6、 Wildcard query
{
'query':{
'wildcard':{
'title':'cr?me'
}
}
}
7、 Regular expression queries
{
'query':{
'regex':{
'title':{
'value':'cr.m[ae]',
'boost':10.0
}
}
}
}
8、 Prefix query
{
'query':{
'match_phrase_prefix':{
'title':{
'query':'crime punish',
'slop':1
}
}
}
}
If there is a mistake , Please point out , thank ~
边栏推荐
- MySQL log management, backup and recovery of databases (2)
- 6. Redis new data type
- Regular expression Basics
- A brief introduction to database mysql
- The human agent of kDa, Jinbei kd6, takes you to explore the metauniverse
- KOREANO ESSENTIAL打造气质职场范
- Article content cannot be copied
- input限制输入
- 【JVM】CMS简述
- Jump table introduction
猜你喜欢

郭琳加冕 2022第三季完美大师 全球人气季军

Quick completion guide for mechanical arm (V): end effector

Article content cannot be copied

MIT-6874-Deep Learning in the Life Sciences Week6
![[AGC] build service 3- authentication service example](/img/32/44547c00476a055557dd1790e18849.png)
[AGC] build service 3- authentication service example

MIT-6874-Deep Learning in the Life Sciences Week5

机械臂速成小指南(四):机械臂关键部件之减速机

孙安民作品《莲花净心》数字藏品上线长城数艺

“昆明城市咖啡地图”活动再度开启

Rider打开Unity脚本后没有提示
随机推荐
浏览器复制的网址粘贴到文档是超链接
Questions about cookies and sessions
Yixian e-commerce released its first quarterly report: adhere to R & D and brand investment to achieve sustainable and high-quality development
"Kunming City coffee map" activity was launched again
鼠标右键打开cmd(命令行)
乡村振兴公益基金启动暨古茶树非遗保护公益行发布
train_de.py: error: argument --save_steps: invalid int value: ‘$[$[889580/128/4]*10/2]‘
The URL copied by the browser and pasted into the document is a hyperlink
Appium automation test foundation - ADB shell command
Chen Haotian won the national championship of the national finals of the 7th children's model star ceremony
力扣 428. 序列化和反序列化 N 叉树 DFS
About the split and join operations of strings
Nlopt -- Nonlinear Optimization -- principle introduction and application method
Action bright: take good care of children's eyes together -- a summary of the field investigation on the implementation of action bright in Guangxi
L'activité "Kunming City coffee map" a rouvert
LVS load balancing
GNN hands on practice (II): reproduction graph attention network gat
陈颢天 荣获第七届少儿模特明星盛典全国总决赛 全国总冠军
郭琳加冕 2022第三季完美大师 全球人气季军
Stack Title: String decoding