第三章 Elasticsearch高级命令【第一章的补充】

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": []
    }
  }
}

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值