1.query string search
GET /ecommerce/product/_search
took: it takes a few milliseconds
timeout: if timeout
_shards: data is split into five slices, so the search request, will hit all of the primary shard (or one of its relica shard can)
hist.total: the number of query results, four total
max_score: Meaning score, it is to document a search for a match score of relevance, the more relevant, the more matches, the higher the score
hits.hits: contains detailed data matching the search of the document
Search product name contains yagao of goods, and in accordance with the price in descending order: GET / ecommerce / product / _search q = name:? Yagao & sort = price: desc
Suitable for temporary use command line tools such as curl, fast read request, to retrieve the desired information. However, if the query requests very complicated, it is difficult to build, in a production environment, rarely use the query string search
2.query DSL
Language Domain Specified Language specific areas: DSL
http request body: the request body, can be used to build json format query syntax, more convenient, you can build a variety of complex syntax, more powerful than the query string search
Query All Products
GET /ecommerce/product/_search
{
“query”:{“match_all”:{}}
}
Query name contains yagao goods, while sorted in descending order of price
GET /ecommerce/product/_search
{
“query”:{
“match”:{
"Name": "yagao"
}
},
“sort”:[
{“price”:”desc”}
]
}
分页查询商品,总共3条商品,假设每页就显示1条商品, 现在显示第二页,所以就查出第二个商品
GET /ecommerce/product/_search
{
“query”:{“match_all”:{}},
“from”:1,
“size”:2
}
指定要查询出来商品的名称和价格
GET /ecommerce/product/_search
{
“query”:{“match_all”:{}},
“_source”:[“name”,”price”]
}
3.query filter(对数据进行过滤)
搜索商品名称包含yagao,而且售价大于25元的商品
GET /ecommerce/product/_search
{
“query”:{
“bool”:{
“must”:[
{“match”:{“name”:”yagao”}}
]
},
“filter”:{
“range”:{
“price”:{
“gt”:25
}
}
}
}
}
4.full-test search(全文检索)
GET /ecommerce/product/_search
{
“query”:{
“match”:{
“product”:”yagao producer”
}
}
}
producer 会被拆解开,建立倒排索引
special 5
yagao 5
producer 1,2,3,5
gaolujie 1
zhonghua 3
jiajieshi 2
Eventually find a match up that data, which is the highest so-called matching
5.phrase search (full text search)
With the corresponding full-text search, on the contrary, the dismantling of the search string entered full-text search will open, go inside to get them inverted index matching, as long as the matching words on any dismantling, can be returned as a result
phrase search, enter a search string of requirements must be specified in the text field, fully contained exactly the same as before they can be considered match, to return as a result.
GET /ecommerce/product/_search
{
“query”:{
“match_phrase”:{“product”:”yagao producter”}
}
}
Only a return data, because they require a full match
6.heighlight search (highlighted search)
GET /ecommerce/product/_search
{
“query”:{
“match”:{
“product”:”producter”
}
},
“highlight”:{
“fields”:{
“product”:{}
}
}
}