-
類似URI Query -- 把查詢條件放在POST裡面
//準備工作 PUT /users/_doc/3 { "name" : "Li Sunke", "about": "php,elasticsearch,redis,nginx,swoole" } PUT /users/_doc/4 { "name" : "Qu Sunke", "about": "mysql,php" } //query_string POST /users/_search { "query": { "query_string": { "query": "Li AND Sunke", "default_field": "name" } } } //返回1個結果 "hits" : [ { "_index" : "users", "_type" : "_doc", "_id" : "3", "_score" : 0.87546873, "_source" : { "name" : "Li Sunke", "about" : "php,elasticsearch,redis,nginx,swoole" } } ] //query string 支援分組查詢多個欄位 // 返回 doc_3 POST /users/_search { "query": { "query_string": { "fields": ["name","about"], "query": "(Li AND Sunke) OR (php AND nginx)" } } }
- 類似Query String ,但是會忽略錯誤的語法同時只支援部分查詢語句
- 不支援 AND OR NOT ,但會當作字串處理
- Term 之間預設的關係是OR,可以指定Operator
- 支援 部分邏輯
-
- 替代 AND
- | 替代OR
- -替代 NOT
// Simple Query 預設的operator 是 Or // AND 會當做一個字串,所以會 3個欄位OR查詢 POST /users/_search { "query": { "simple_query_string": { "query": "Li AND Sunke", "fields": ["name"], "default_operator": "AND" } } } // default_operator 是 OR //只返回一條結果 POST /users/_search { "query": { "simple_query_string": { "query": "Li Sunke", "fields": ["name"], "default_operator": "AND" } } }
-
本作品採用《CC 協議》,轉載必須註明作者和本文連結