ES查詢示例

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": "*華為手機(jī)*"

? ? }}


}}

11、模糊搜索+多條件查詢

GET indexName/_search

{

? "query":{


? ? ? "bool": {

? ? ? "filter": [

? ? ? ? {

? ? ? ? ? "term": {

? ? ? ? ? ? "processDate": {

? ? ? ? ? ? ? "value": "2020-12-16"

? ? ? ? ? ? }

? ? ? ? ? }

? ? ? ? },? ? { "query_string": {

? ? ? ? "default_field": "requireId",

? ? ? ? "query" : "*20121617568893*"

? ? ? }}

? ? ? ]

? ? }


? }

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • pyspark.sql模塊 模塊上下文 Spark SQL和DataFrames的重要類: pyspark.sql...
    mpro閱讀 9,915評論 0 13
  • 1、ValueError: Incompatible indexer with Series 一般是datafra...
    Rainysong閱讀 15,017評論 0 8
  • 一. AD DS簡介 Active Directory域服務(wù) (AD DS) 可存儲有關(guān)網(wǎng)絡(luò)上的用戶、計(jì)算機(jī)和其他...
    shuhanghang閱讀 3,346評論 1 5
  • 一、基本屬性介紹 1.包含搜索和聚合兩大功能 2.天生分布式結(jié)構(gòu),支持水平擴(kuò)展,可以是多個(gè)節(jié)點(diǎn)甚至是幾百個(gè)節(jié)點(diǎn) 3...
    布魯_boy閱讀 4,628評論 1 1
  • 此文是關(guān)于elasticsearch in action書部分重點(diǎn)讀書筆記。 Chapter 2 Diving i...
    shamumu閱讀 2,730評論 0 1

友情鏈接更多精彩內(nèi)容