定義索引結構app
DELETE telegraph PUT telegraph { "mappings": { "msg":{ "properties": { "title":{ "type": "text", "analyzer": "ik_max_word" }, "content":{ "type": "text", "analyzer": "ik_max_word" }, "author":{ "type": "text" }, "pubdate":{ "type": "date", "format": "date_hour_minute_second" } } } } }
批量加入測試數據測試
POST _bulk {"index":{"_index":"telegraph","_type":"msg"}} {"title":"寶泰隆:半年報預增140%-156%","content":"公司主要產品焦炭、甲醇銷售量及銷售價格較上年同期有較大的上漲","author":"寶泰隆","pubdate":"2018-07-17T17:16:30"} {"index":{"_index":"telegraph","_type":"msg"}} {"title":"週五召開董事會會議 審議及批准更新後的一季報","content":"以審議及批准更新後的2018年第一季度報告","author":"中興通信","pubdate":"2018-07-17T12:33:11"} {"index":{"_index":"telegraph","_type":"msg"}} {"title":"長生生物再次跌停 三機構拋售近1000萬元","content":"長生生物再次一字跌停,報收19.89元,成交1432萬元","author":"長生生物","pubdate":"2018-07-17T10:03:11"} {"index":{"_index":"telegraph","_type":"msg"}} {"title":"碧桂園集團副主席楊惠妍","content":"楊惠妍分別於7月10日、11日買入碧桂園1000萬股、1500萬股","author":"小財注","pubdate":"2018-07-17T16:12:55"} {"index":{"_index":"telegraph","_type":"msg"}} {"title":"河北聚焦十大行業推動國際產能合做","content":"河北省政府近日出臺積極參與「一帶一路」建設推動國際產能合做實施方案","author":"財聯社","pubdate":"2018-07-17T14:14:55"}
GET telegraph/_search { "query": { "term": { "title": { "value": "主席" } } } }
查詢結果spa
{ "took": 5, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 1, "max_score": 0.2876821, "hits": [ { "_index": "telegraph", "_type": "msg", "_id": "A5etp2QBW8hrYY3zGJk7", "_score": 0.2876821, "_source": { "title": "碧桂園集團副主席楊惠妍", "content": "楊惠妍分別於7月10日、11日買入碧桂園1000萬股、1500萬股", "author": "小財注", "pubdate": "2018-07-17T16:12:55" } } ] } }
from:起始行code
size:返回條數orm
GET telegraph/_search { "from": 0, "size": 3, "query": { "match_all": {} } }
查詢結果索引
{ "took": 6, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 5, "max_score": 1, "hits": [ { "_index": "telegraph", "_type": "msg", "_id": "AZetp2QBW8hrYY3zGJk7", "_score": 1, "_source": { "title": "週五召開董事會會議 審議及批准更新後的一季報", "content": "以審議及批准更新後的2018年第一季度報告", "author": "中興通信", "pubdate": "2018-07-17T12:33:11" } }, { "_index": "telegraph", "_type": "msg", "_id": "A5etp2QBW8hrYY3zGJk7", "_score": 1, "_source": { "title": "碧桂園集團副主席楊惠妍", "content": "楊惠妍分別於7月10日、11日買入碧桂園1000萬股、1500萬股", "author": "小財注", "pubdate": "2018-07-17T16:12:55" } }, { "_index": "telegraph", "_type": "msg", "_id": "AJetp2QBW8hrYY3zGJk7", "_score": 1, "_source": { "title": "寶泰隆:半年報預增140%-156%", "content": "公司主要產品焦炭、甲醇銷售量及銷售價格較上年同期有較大的上漲", "author": "寶泰隆", "pubdate": "2018-07-17T17:16:30" } } ] } }
指定只須要返回的字段值ip
GET telegraph/_search { "_source": ["title","content"], "query": { "term": { "title": { "value": "主席" } } } }
查詢結果文檔
{ "took": 13, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 1, "max_score": 0.2876821, "hits": [ { "_index": "telegraph", "_type": "msg", "_id": "A5etp2QBW8hrYY3zGJk7", "_score": 0.2876821, "_source": { "title": "碧桂園集團副主席楊惠妍", "content": "楊惠妍分別於7月10日、11日買入碧桂園1000萬股、1500萬股" } } ] } }
設置version字段爲true,顯示文檔版本號產品
GET telegraph/_search { "_source": "title", "version": true, "query": { "term": { "title": { "value": "主席" } } } }
查詢結果it
{ "took": 8, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 1, "max_score": 0.2876821, "hits": [ { "_index": "telegraph", "_type": "msg", "_id": "A5etp2QBW8hrYY3zGJk7", "_version": 1, "_score": 0.2876821, "_source": { "title": "碧桂園集團副主席楊惠妍" } } ] } }
過濾知足最小評分的文檔
GET telegraph/_search { "min_score":"0.2", "query": { "term": { "title": { "value": "碧桂園" } } } }
查詢結果
{ "took": 5, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 1, "max_score": 0.2876821, "hits": [ { "_index": "telegraph", "_type": "msg", "_id": "A5etp2QBW8hrYY3zGJk7", "_score": 0.2876821, "_source": { "title": "碧桂園集團副主席楊惠妍", "content": "楊惠妍分別於7月10日、11日買入碧桂園1000萬股、1500萬股", "author": "小財注", "pubdate": "2018-07-17T16:12:55" } } ] } }
設置屬性,且該屬性中有對應查詢條件的關鍵字時高亮顯示。
GET telegraph/_search { "query": { "term": { "title": { "value": "會議" } } }, "highlight": { "fields": { "title": {} } } }
查詢結果
{ "took": 9, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 1, "max_score": 0.2876821, "hits": [ { "_index": "telegraph", "_type": "msg", "_id": "AZetp2QBW8hrYY3zGJk7", "_score": 0.2876821, "_source": { "title": "週五召開董事會會議 審議及批准更新後的一季報", "content": "以審議及批准更新後的2018年第一季度報告", "author": "中興通信", "pubdate": "2018-07-17T12:33:11" }, "highlight": { "title": [ "週五召開董事會<em>會議</em> 審議及批准更新後的一季報" ] } } ] } }