ElasticSearch6.2.4(3)——簡單的搜尋方式
- PUT /zoo/product/1
- {
- "name":"monkey",
- "age":10,
- "content":"xiao small but ke ai"
- }
- PUT /zoo/product/2
- {
- "name":"monkey",
- "age":13,
- "content":"xiao small but very big"
- }
- PUT /zoo/product/3
- {
- "name":"dog",
- "age":13,
- "content":"xiao big but very small"
- }
- PUT /zoo/product/4
- {
- "name":"cat",
- "age":18,
- "content":"xiao big but very small"
- }
- PUT /zoo/product/5
- {
- "name":"tig",
- "age":30,
- "content":"xiao big but very big"
- }
2.搜尋zoo下面product的所有document
GET /zoo/product/_search
took:耗費了幾毫秒
timed_out:是否超時,這裡是沒有
_shards:資料拆成了5個分片,所以對於搜尋請求,會打到所有的primary shard(或者是它的某個replica shard也可以)
hits.total:查詢結果的數量,3個document
hits.max_score:score的含義,就是document對於一個search的相關度的匹配分數,越相關,就越匹配,分數也高
hits.hits:包含了匹配搜尋的document的詳細資料
3.查詢所有動物
- GET /zoo/product/_search
- {
- "query": {
- "match_all": {}
- }
- }
4.查詢包含big的內容,並且按照age降序(desc是降序,asc是升序)
- GET /zoo/product/_search
- {
- "query": {
- "match": {
- "content": "big"
- }
- },
- "sort": [
- {
- "age": {
- "order": "desc"
- }
- }
- ]
- }
5.從0下標開始查詢出2包含big的動物
- GET /zoo/product/_search
- {
- "query": {
- "match": {
- "content": "big"
- }
- },
- "size": 2,
- "from": 0
- }
6.查詢出來的資料只要age和content屬性
- GET /zoo/product/_search
- {
- "_source": ["age","content"]
- }
7.查詢出包含big but整段短語
- GET /zoo/product/_search
- {
- "query": {
- "match_phrase": {
- "content": "big but"
- }
- }
- }
8.查詢出來的資料進行高亮處理
1.準備工作,新增資料
- GET /zoo/product/_search
- {
- "query": {
- "match": {
- "content": "big but"
- }
- },
- "highlight": {
- "fields": {
- "content": {}
- }
- }
- }
- PUT /zoo/product/1
- {
- "name":"monkey",
- "age":10,
- "content":"xiao small but ke ai"
- }
- PUT /zoo/product/2
- {
- "name":"monkey",
- "age":13,
- "content":"xiao small but very big"
- }
- PUT /zoo/product/3
- {
- "name":"dog",
- "age":13,
- "content":"xiao big but very small"
- }
- PUT /zoo/product/4
- {
- "name":"cat",
- "age":18,
- "content":"xiao big but very small"
- }
- PUT /zoo/product/5
- {
- "name":"tig",
- "age":30,
- "content":"xiao big but very big"
- }
2.搜尋zoo下面product的所有document
GET /zoo/product/_search
took:耗費了幾毫秒
timed_out:是否超時,這裡是沒有
_shards:資料拆成了5個分片,所以對於搜尋請求,會打到所有的primary shard(或者是它的某個replica shard也可以)
hits.total:查詢結果的數量,3個document
hits.max_score:score的含義,就是document對於一個search的相關度的匹配分數,越相關,就越匹配,分數也高
hits.hits:包含了匹配搜尋的document的詳細資料
3.查詢所有動物
- GET /zoo/product/_search
- {
- "query": {
- "match_all": {}
- }
- }
4.查詢包含big的內容,並且按照age降序(desc是降序,asc是升序)
- GET /zoo/product/_search
- {
- "query": {
- "match": {
- "content": "big"
- }
- },
- "sort": [
- {
- "age": {
- "order": "desc"
- }
- }
- ]
- }
5.從0下標開始查詢出2包含big的動物
- GET /zoo/product/_search
- {
- "query": {
- "match": {
- "content": "big"
- }
- },
- "size": 2,
- "from": 0
- }
6.查詢出來的資料只要age和content屬性
- GET /zoo/product/_search
- {
- "_source": ["age","content"]
- }
7.查詢出包含big but整段短語
- GET /zoo/product/_search
- {
- "query": {
- "match_phrase": {
- "content": "big but"
- }
- }
- }
8.查詢出來的資料進行高亮處理
- GET /zoo/product/_search
- {
- "query": {
- "match": {
- "content": "big but"
- }
- },
- "highlight": {
- "fields": {
- "content": {}
- }
- }
- }