GET _cat/indices
#查看所有表
對個(gè)字段都要求和?
字段值去重統(tǒng)計(jì)與顯示ok
空數(shù)組的記錄
must、should混合使用
----------數(shù)據(jù)類型--------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
GET查、PUT增/改、POST增 和 DELETE刪
POST不用加具體的id,它是作用在一個(gè)集合資源之上的,而PUT操作是作用在一個(gè)具體資源之上的
POST /website/blog/1/_update
{
"doc" : {
"aa" :"bbb",
"123": 0
}
}
#更新部分documents,僅更新aa字段和123字段,不會(huì)整個(gè)文檔更新
PUT /customer/external/1?pretty
{
"name": "John Doe"
}
#必須有參數(shù)文檔id無則報(bào)錯(cuò),id不存在會(huì)自動(dòng)創(chuàng)建存在則覆蓋(注意:PUT會(huì)將新的json值完全替換掉舊的,整個(gè)文檔覆蓋)
POST /customer/external?pretty
{
"name": "Jane Doe"
}
#不指定id創(chuàng)建時(shí)document需要使用POST命令,會(huì)自動(dòng)生成id 如:AVpQdsOSxaunvQAUZY5w
DELETE /customer/external/1?pretty
#刪除documents
------------------------------------------------------------------------------------------
mysql數(shù)據(jù)庫database相當(dāng)于 es索引index
mysql表table 相當(dāng)于 es類型type
mysql數(shù)據(jù)行row 相當(dāng)于 es文檔document
mysql數(shù)據(jù)列column 相當(dāng)于 es字段field
bool 實(shí)現(xiàn)復(fù)合查詢
sort排序
"from" : 0, "size" : 200 控制指定數(shù)量
_source 返回指定字段
"sort": 允許我們將檢索的結(jié)果以指定的字段進(jìn)行排序顯示
match_all 查詢所有
match 模糊匹配,將被查詢值進(jìn)行分詞
match_phrase 完全匹配,查詢指定段落
term 查詢時(shí)判斷某個(gè)document是否包含某個(gè)具體的值,不會(huì)對被查詢的值進(jìn)行分詞查詢
range 作區(qū)間搜索(日期區(qū)間或數(shù)值區(qū)間)
gte: 大于或等于
gt: 大于
lte: 小于或等于
lt: 小于
boost: 設(shè)置查詢的提升值,默認(rèn)為1.0
"cardinality": 字段值去重統(tǒng)計(jì)
"collapse": 返回去重內(nèi)容
GET /national_credit_company_analysis/company_analysis/_mapping
#查看字段類型
GET /national_credit_company_news_list/_search
{
"query": {
"match": {
"field_id": "03"
}
},
"sort": [
{
"published": {
"order": "desc"
}
}
]
}
#排序
GET /national_credit_company_news_list/_search
{
"query": {
"match_all": {
}
}
}
#match_all 查詢?nèi)?/div>
GET /national_credit_event_news_list/_search
{
"query": {
"bool": {
"must_not": {
"match_phrase": {
"subject_involved_id": """"[]"""
}
}
}
}
}
GET /national_credit_subject_news_analysis/_search
{
"query": {
"match_phrase": {
"task_id": "86"
}
},
"aggs": {
"a2": {
"sum": {
"field": "negative_num"
}
}
}
}
#sum 求和 、min 最小值 、max最大值、avg平均值
GET /national_credit_subject_news_list/_search
{
"query": {
"terms": {
"task_id": [
"86",
"87"
]
}
}
}
#值or
GET /national_credit_subject_news_list/_search
{
"query": {
"bool": {
"must": [
{"term":{ "task_id": "86"}},
{"term":{ "title": "新零售 從概念走向現(xiàn)實(shí)"}}
]
}
}
}
GET /national_credit_subject_news_list/_search
{
"query": {
"bool": {
"must": [
{"match_phrase":{ "body": "信用服務(wù)機(jī)構(gòu)"}}
],
"must_not": [
{"match_phrase":{ "title": "信用服務(wù)機(jī)構(gòu)"}}
]
}
}
}
GET /national_credit_subject_news_list/_search
{
"query": {
"bool": {
"should": [
{"match_phrase":{ "body": "信用服務(wù)機(jī)構(gòu)"}},
{"match_phrase":{ "title": "信用服務(wù)機(jī)構(gòu)"}}
]
}
}
}
GET /national_credit_hot_news_list/_search
{"query":{"bool":{
"must":[
{"match_phrase":{"status":"0"}},
{"bool":{
"should":[
{"match_phrase":{"body":"信用服務(wù)機(jī)構(gòu)"}},
{"match_phrase":{"title":"信用服務(wù)機(jī)構(gòu)"}}
]}}]}}}
#must和should混合
#must :多個(gè)查詢條件的完{}全匹配,相當(dāng)于 and
#must_not :多個(gè)查詢條件的相反匹配,相當(dāng)于 not
#should :至少有一個(gè)查詢條件匹配, 相當(dāng)于 or
GET /national_credit_evaluation_news_list/_search
{
"_source": ["enterprise_name","status"],
"query": {
"term": {
"status": "0"
}
}
}
#_source 返回指定字段
GET /national_credit_evaluation_news_list/_search
{
"size": 0,
"query": {
"match_phrase": {
"status":"0"
}
},
"aggs": {
"distinct": {
"cardinality": {"field" :"enterprise_name.keyword"}
}
}
}
#統(tǒng)計(jì)某個(gè)字段值去重后數(shù)量
GET /national_credit_evaluation_news_list/_search
{
"from" : 0, "size" : 100,
"_source": "",
"query": {
"match_phrase": {
"status": "0"
}
},
"collapse": {"field" :"enterprise_name.keyword"}
}
#返回去重內(nèi)容
GET /national_credit_subject_news_analysis/_search
{
"size": 1,
"query": {
"bool": {
"must": [
{"match_phrase": {
"task_id": "96"
}},
{"range": {
"date": {
"gte": "2018-01-28",
"lte": "2018-01-28"
}
}}
]
}
},
"aggs": {
"negative_num": {
"sum": {"field": "negative_num"}
}
}
}
#---某個(gè)專題某個(gè)時(shí)間段統(tǒng)計(jì)信息
GET /national_credit_all_news/_search
{
"query": {
"range": {
"update_time": {
"gte": "2019-01-28 00:00:00",
"lte": "2019-01-27 23:59:59"
}
}
}
}
#range 時(shí)間范圍
################################################
PUT /national_credit_company_news_list/_settings
{
"max_result_window" : 100000000
}
浙公網(wǎng)安備 33010602011771號