当前位置:网站首页>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 ~
边栏推荐
- MIT-6874-Deep Learning in the Life Sciences Week4
- "Kunming City coffee map" activity was launched again
- Deployment of efficient and versatile clusters lvs+kept highly available clusters
- MySQL index, transaction and storage engine of database (3)
- Guolin was crowned the third place of global popularity of perfect master in the third quarter of 2022
- 事件对象的说明》
- 【JVM】G1垃圾回收器簡述
- Cobbler Automated Deployment
- Highlight display of Jinbei LB box, adhering to mini special effects
- 2022 Season 6 perfect children's model toxon division finals came to a successful conclusion
猜你喜欢

Koreano essential creates a professional style

光明行动:共同呵护好孩子的眼睛——广西实施光明行动实地考察调研综述

Article content cannot be copied

Appium automation test foundation - 12 Introduction to appium automated testing framework

MySQL index, transaction and storage engine of database (1)

Rider does not prompt after opening unity script

【JVM】G1垃圾回收器簡述

MIT-6874-Deep Learning in the Life Sciences Week4

unable to convert expression into double array

‘Failed to fetch current robot state‘ when using the ‘plan_kinematic_path‘ service #868
随机推荐
【JVM】CMS简述
‘Failed to fetch current robot state‘ when using the ‘plan_kinematic_path‘ service #868
《锦绣中华》中老年公益文旅游-走进佛山敬老院
2022第六季完美童模 合肥赛区 初赛圆满落幕
Rider打开Unity脚本后没有提示
Brève description du collecteur d'ordures G1
著名画家史国良《丰收时节》数字藏品上线长城数艺
G 代码解释|最重要的 G 代码命令列表
Detailed explanation of SolidWorks mass characteristics (inertia tensor, moment of inertia, inertia spindle)
机械臂速成小指南(五):末端执行器
Chen Haotian won the national championship of the national finals of the 7th children's model star ceremony
基于强化学习的股票量化交易Automated-Stock-Trading-Ensemble-Strategy
Memorize the text and remember the words. Read the text and remember the words. Read the article and remember the words; 40 articles with 3500 words; 71 articles broke through the words in the middle
Shell script functions
MIT-6874-Deep Learning in the Life Sciences Week5
Stack Title: String decoding
Yixian e-commerce released its first quarterly report: adhere to R & D and brand investment to achieve sustainable and high-quality development
G code explanation | list of the most important G code commands
MySQL log management, backup and recovery of databases (1)
Didn't receive robot state (joint angles) with recent timestamp within 1 seconds