当前位置:网站首页>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 ~
边栏推荐
- Questions about cookies and sessions
- 事件对象的说明》
- Eth is not connected to the ore pool
- 文章内容无法复制复制不了
- The URL copied by the browser and pasted into the document is a hyperlink
- MySQL index, transaction and storage engine of database (3)
- 6.Redis新数据类型
- KOREANO ESSENTIAL打造气质职场范
- unable to convert expression into double array
- Deploy lvs-dr cluster
猜你喜欢

Deploy lvs-dr cluster

Js获取指定字符串指定字符位置&指定字符位置区间的子串【简单详细】

KOREANO ESSENTIAL打造气质职场范

Theme Studio

Yixian e-commerce released its first quarterly report: adhere to R & D and brand investment to achieve sustainable and high-quality development

Installation and use

KOREANO ESSENTIAL打造气质职场范

“昆明城市咖啡地图”再度开启,咖啡拉近城市距离

MySQL log management, backup and recovery of databases (2)

MIT-6874-Deep Learning in the Life Sciences Week5
随机推荐
Quick completion guide for manipulator (4): reducer of key components of manipulator
Harvester ch1 of CKB and HNS, connection tutorial analysis
A brief introduction to database mysql
9. cache optimization
train_ de.py: error: argument --save_ steps: invalid int value: ‘$[$[889580/128/4]*10/2]‘
MIT-6874-Deep Learning in the Life Sciences Week6
OSError: [Errno 28] No space left on device
二极管如何工作?
Yixian e - commerce publie un rapport trimestriel: adhérer à la R & D et à l’investissement de la marque, réaliser un développement durable et de haute qualité
"Kunming City coffee map" activity was launched again
调试方法和技巧详解
[AGC] build service 3- authentication service example
KOREANO ESSENTIAL打造气质职场范
孙安民作品《莲花净心》数字藏品上线长城数艺
The preliminary round of the sixth season of 2022 perfect children's model Hefei competition area was successfully concluded
Koreano essential creates a professional style
Input limit input
“昆明城市咖啡地图”活动再度开启
乡村振兴公益基金启动暨古茶树非遗保护公益行发布
MySQL advanced SQL statement of database (1)