1. 搜索全部文档
GET /索引库/类型/_search
{
"query": {
"match_all": {}
}
}
2. 脚本字段
用例:订单中有不同的汇率,结合汇率对订单价格进行排序
GET /索引库/类型/_search
{
"script_fields": {
"产生的脚本字段的名称": {
"script": {
"lang": "painless",#默认使用painless 但是还有expression支持各种数学运算
"source": "doc['索引字段名'].value+'hello'"
}
}
}
, "query": {
"match_all": {}
}
}
示例一
GET /dongkuijieit/user/_search
{
"script_fields": {
"new_field": {
"script": {
"lang": "painless",
"source": "doc['age'].value +'hello'"
}
}
}
, "query": {
"match_all": {}
}
}
结果:
示例二
PUT my_index/_doc/1
{
"my_field": 5
}
GET my_index/_search
{
"script_fields": {
"my_doubled_field": {
"script": {
"lang": "expression",
"source": "doc['my_field'] * multiplier",
"params": {
"multiplier": 2
}
}
}
}
}
结果:
3.短语搜索 match Parse
GET /索引库/类型/_search
{
"query": {
"match_phrase": {
"字段名称":{
"query": "内容",
"slop": 1 #间隔空格
}
}
}
}
4.Query String Query
GET /索引库/类型/_search
{
"query": {
"query_string": {
"default_field": "FIELD",
"query": "this AND that OR thus"
}
}
}
5. Simple Query String Query
1.不支持and or not
会当字符串处理
2.Trem之间默认的关系时OR ,可以指定Operator
3.支持逻辑 + 替换AND
|替换OR
-替换NOT
示例:
GET /索引库/类型/_search
{
"query": {
"simple_query_string": {
"query": "",
"fields": []
}
}
}