• java代码实现搜索elasticsearch索引数据


    1、关于获取客户端以及增删改操作请看上一篇文章,文章中有详细的讲解

    2、本篇文章讲述关于elasticsearch搜索匹配方式,主要有 match、match_phrase、term、regexp、wildcard、range和分页以及排序的方法

      (1)、分页查询数据,对结果进行排序完整格式为

    {
        "from" :0, "size" :20,
        "query": {
              "match_all":{}
        },"sort": [{ "排序字段": { "order": "desc" }}]
    } 
    

      (2)、各种查询匹配格式(重要部分)

      match:分词匹配   "match": { "epNo" : "我是人" }  //匹配epNo包含 '我'   ‘是’   ‘人’   的数据,会将一个整的语句拆成一个字一个字的

      match_phrase:不分词匹配      "match_phrase": { "epNo" : "123456" }  //匹配epNo包含123456的数据

      term:完全匹配     "term": { "epNo" : "123456" }  //匹配epNo等于123456的数据

      regexp:正则匹配     "regexp": { "epNo" : "*123456*" }  //匹配epNo包含123456的数据

      wildcard:表达式匹配    "wildcard": { "epNo" : "*123456*" }  //匹配epNo包含123456的数据

      range:区间范围匹配    "range": { "goodsPrice": { "gte":20,"lte":50 } }  //匹配价钱在20~40中间的数据

      (3)、should的使用

      为了保证should中的条件至少有一个存在,语法如下

      "must": [
        {
          "bool": {
              "should": [
              { "match_phrase": { "goodsSubtitle": { "query" : "游戏", "boost" : 5 }}},
              { "match_phrase": { "goodsName": { "query" : "游戏", "boost" : 5 }}}
              ]
            }
        }
      ]

  • 相关阅读:
    为什么转速环经过pi调节后输出的是电流?
    如何将mysql、php、nginx设置为开机自启动
    rm-rf /*
    2020/4/23-linux中的定时任务详解
    2020/4/20 一键部署服务
    2020/4/20-ansible一键部署nfs
    2020/4/20-backup之rsync
    2020/4/19-linux中/etc/hosts
    2020/4/18-linux中的selinux
    2020/4/18-linux中的iptables
  • 原文地址:https://www.cnblogs.com/lazycxy/p/9475683.html
Copyright © 2020-2023  润新知