查询
- 字符串查询:
_search!q=age:22
DSL
- match_all 查询所有
match
对于所给的内容进行analyzer后查询(term 是查询的最小单位)
全文查询
GET /_search
{
"query": {
"match" : {
"message" : {
"query" : "this is a test",
"operator" : "and"
}
}
}
}
this is a test
之间的关系是and
match_phrase
按短语查询, 只有存在这个短语的文档才会被显示出来(精准匹配)
https://blog.csdn.net/timothytt/article/details/86775114
- match_phrase 还是需要分词, 目标文档需要包行分词后的所有词, 顺序要保持一致
- term 语句对于中文查询时, 目标文本会被划分为单个字, 使得整个term无法被查到
term
按照字段做精准匹配
bool
多条件查询, 可以使用list在一子查询中加入多条查询, 默认为should条件
- should 对算分有贡献
minmum_should_match: 1 至少匹配一个should
//新增多筆資料
POST /products/_bulk
{
"index": {
"_id": 1 }}
{
"price" : 10,"avaliable":true,"date":"2018-01-01", "productID" : "XHDK-A-1293-#fJ3" }
{
"index": {
"_id": 2 }}
{
"price" : 20,"avaliable":true,"date":"2019-01-01", "productID" : "KDKE-B-9947-#kL5" }
{
"index": {
"_id": 3 }}
{
"price" : 30,"avaliable":true, "productID" : "JODL-X-1937-#pV7" }
{
"index": {
"_id": 4 }}
{
"price" : 30,"avaliable":false, "productID" : "QQPX-R-3956-#aD8" }
//bool query,使用多個子查詢
POST /products/_search
{
"query": {
"bool" : {
//Query Context
"must" : {
"term" : {
"price" : "30" }
},
//Filter Context
"filter": {
"term" : {
"avaliable" : "true" }
},
//Filter Context
"must_not" : {
"range" : {
"price" : {
"lte" : 10 }
}
},
//Query Context
"should" : [
{
"term" : {
"productID.keyword" : "JODL-X-1937-#pV7" } },
{
"term" : {
"productID.keyword" : "XHDK-A-1293-#fJ3" } }