首页 > 其他分享 >Elastic_Dev_Tools

Elastic_Dev_Tools

时间:2024-11-14 08:50:37浏览次数:1  
标签:search Elastic GET type hotel Dev query Tools match

GET _search
{
  "query": {
    "match_all": {}
  }
}

GET /_analyze
{
  "analyzer": "ik_smart",
  "text": "我爱北京天安门"
}
# 创建表
PUT /user
{
  "mappings": {
    "properties": {
      "age": {
        "type": "integer",
        "index": true
      },
      "info": {
        "type": "text",
        "analyzer": "ik_smart"
      },
      "email": {
        "type": "keyword"
      },
      "name": {
        "type": "object", 
        "properties": {
          "firstName": {
            "type": "keyword"
          },
          "lastName": {
            "type": "keyword"
          }
          
        }
      }
    }
  }
}
#查看索引库
GET /hotel
#删除索引库
DELETE /user
#修改索引库
PUT /user/_mapping
{
  "properties": {
    "weight": {
      "type": "double"
    }
  }
}

#文档操作
#新建文档
POST /user/_doc/
{
  "age":30,
  "email":"张@qq.com",
  "info":"JAVA高级程序员",
  "name":{
    "firstName":"张",
    "lastName": "123"
  },
  "weight":"75"
}
#查询索引库所有数据
GET /user/_search
{
  "query": {
    "match_all": {}
  }
}
#查询某一个文档数据
GET /user/_doc/1
#删除某一个文档数据
DELETE /user/_doc/lDD-FJMBA6ani3V3HjCM
#修改文档数据
#全局修改
PUT /user/_doc/1
{
  "age":30,
  "email":"[email protected]",
  "info":"JAVA高级程序员",
  "name":{
    "firstName":"蒋",
    "lastName":"欢欢"
  },
  "weight":"75"
}
#局部修改
POST /user/_update/1
{
  "doc": {
    "age":66
  }
}

#创建hotel索引库
PUT /hotel
{
  "mappings": {
    "properties": {
      "id": {
        "type": "keyword"
      },
      "name":{
        "type": "text",
        "analyzer": "ik_max_word",
        "copy_to": "all"
      },
      "address":{
        "type": "keyword",
        "index": false
      },
      "price":{
        "type": "integer"
      },
      "score":{
        "type": "integer"
      },
      "brand":{
        "type": "keyword",
        "copy_to": "all"
      },
      "city":{
        "type": "keyword",
        "copy_to": "all"
      },
      "starName":{
        "type": "keyword",
         "copy_to": "all"
      },
      "business":{
        "type": "keyword"
      },
      "location":{
        "type": "geo_point"
      },
      "pic":{
        "type": "keyword",
        "index": false
      },
      "isAd":{
        "type": "text"
      },
      "all":{
        "type": "text",
        "analyzer": "ik_max_word"
      }
    }
  }
}
GET /hotel
DELETE /hotel
#查询索引库所有数据
GET /hotel/_search
{
  "query": {
    "match_all": {}
  }
}
#全文检索的match查询
GET /hotel/_search
{
  "query": {
    "match": {
      "all": "如家"
    }
  }
}
#全文检索的multi_match查询
GET /hotel/_search
{
  "query": {
    "multi_match": {
      "query": "如家",
      "fields": ["brand","city","name"]
    }
  }
}
#精确查询term
GET /hotel/_search
{
  "query": {
    "term": {
      "brand": {
        "value": "丽笙"
      }
    }
  }
}
#精确查询range
GET /hotel/_search
{
  "query": {
    "range": {
      "price": {
        "gte": 200,
        "lte": 300
      }
    }
  }
}

#地理坐标查询 geo_distance
GET /hotel/_search
{
  "query": {
    "geo_distance":{
      "distance": "1.5km",
      "location": "31.21,121.5"
    }
  }
}

#复合型查询:function_score---广告置顶
GET /hotel/_search
{
  "query": {
  "function_score": {
    "query": {
      "match": {
        "all": "如家"
      }
    },
    "functions": [
      {
        "filter": {
         "range": {
           "price": {
             "gte": 300,
             "lte": 450
           }
         }
        },
        "weight": 10
      } 
    ],
    "boost_mode": "multiply"
  }   
  }
}


GET /hotel/_search
{
"sort": [
  {
    "price": {
      "order": "desc"
    }
  },
  
  {
    "_geo_distance": {
      "location": "31.25,121.5",
      "order": "asc"
    
     }
   }
  ] 
}
  
}

GET /hotel/_search---广告置顶
{
  "query": {
    "function_score": {
      "query": {
        "match": {
          "all": "如家"
        }
      },
      "functions": [
        {
         "filter": {
           "term": {
             "city": "北京"
           }
         },
         "weight": 10
        }
       
      ]
    }
  }
}

GET /hotel/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {}
        }
      ],
      "filter": [
        {
          "geo_distance": {
            "distance": "10km",
            "location": {
              "lat": 31.21,
              "lon": 121.5
            }
          }
        }
      ]
    }
  }
}



GET /hotel/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {}
        }
      ],
      "filter": [
        {
          "term": {
            "city": "北京"
          }
        },
        {
          "term": {
            "brand": "如家"
          }
        }
      ]
    }
  },
  "sort": [
    {
     "_geo_distance": {
       "location": {
         "lat": 31.25,
         "lon": 121.5
       },
       "order": "asc"
     }
    },
    {
      "price": {
        "order": "desc"
      }
    }
  ],
  "highlight": {
    "fields": {
      "name": {
        "pre_tags": "<em>",
        "post_tags": "</em>",
        "require_field_match": "false"
      }
    }
  }
}


#结果集排序
GET /hotel/_search
{
  "query": {
    "match_all": {}
  },
  "sort": [
    {
      "price": {
        "order": "desc"
      }
    }
  ]
}

GET /hotel/_search
{
  "query": {
    "match_all": {}
  },
  "sort": [
    {
      "_geo_distance": {
        "location": {
          "lat": 31.21,
          "lon": 121.5
        },
        "order": "asc"
      }
    }
  ]
}

GET /hotel/_search
{
  "query": {
    "match_all": {}
  },
  "sort": [
    {
      "score": {
        "order": "desc"
      },
      "price": {
        "order": "asc"
      }
    }
  ]
}

GET /hotel/_search
{
  "query": {
    "match_all": {}
  },
  "sort": [
    {
      "isAD": {
        "order": "desc"
      }
    }
  ]
}

GET /hotel/_search
{
  "query": {
    "match_all": {}
  },
  "from": 191,
  "size": 10,
  "sort": [
    {
      "price": {
        "order": "asc"
      }
    }
  ]
}

GET /hotel/_search
{
  "query": {
    "match": {
      "name": "如家"
    }
  },
  "highlight": {
    "fields": {
      "name": {
       "pre_tags": "<em>",
       "post_tags": "</em>"
      }
    }
  }
}

GET /hotel/_search
{
  "query": {
    "match": {
      "brand": "如家"
    }
  },
  "highlight": {
    "fields": {
      "name": {
        "pre_tags": "<em>",
        "post_tags": "</em>",
        "require_field_match": "false"
      }
    }
  }
}

POST /hotel/_update/197837109
{
    "doc": {
        "isAD": true
    }
}
POST /hotel/_update/1557882030
{
    "doc": {
        "isAD": true
    }
}
POST /hotel/_update/197492277
{
    "doc": {
        "isAD": true
    }
}
POST /hotel/_update/200214824
{
    "doc": {
        "isAD": true
    }
}





GET /hotel/_search
{
  "query": {
   "match_all": {} 
  },
  "from": 191,
  "size": 10
}

GET /hotel/_search
{
  "query": {
    "match": {
      "all": "上海"
    }
  }
}


标签:search,Elastic,GET,type,hotel,Dev,query,Tools,match
From: https://www.cnblogs.com/xwdzj/p/18545217

相关文章

  • IEMS5731 Software Design and Development
    IEMS5731SoftwareDesignandDevelopment(Fall2024)IndividualCourseProjectSpecification-MasterMindExpectedtime:10hoursLearningoutcomes:TopractiseGUIbuttons,labelsandpanelsinJava.ToexperiencetheMVCpatternviaaGUIMasterMind.......
  • CHC5028 Software Development
    CHC5028SoftwareDevelopmentwithC/C++CourseworkImportantDates Background“Textadventures”,nowcalled“interactivefiction”,wereamongthefirsttypeofcomputergameeverproduced.Thesegameshavenographics;theplayerreadsthestoryof......
  • 推荐一个Elasticsearch ES可视化客户端工具:ES-King
    ES-King:开源免费,一个现代、实用的ESGUI客户端,支持多平台。下载地址:https://github.com/Bronya0/ES-King功能清单详尽的集群信息:节点信息、堆内存占用、总内存占用、cpu占用、磁盘占用、网络流量、节点角色、集群健康、5分钟负载、每个节点的字段缓存、段缓存、查询缓存、请求......
  • 题解:[XIX Open Cup, Grand Prix of Korea] Dev, Please Add This!
    前置知识:2-SAT题意[XIXOpenCup,GrandPrixofKorea]Dev,PleaseAddThis!在一张网格上有以下几种物品:空地(.)墙(#)星星(*)一个球(O)现在你要玩一个游戏。你可以让球朝上下左右某一个方向移动,但是一旦移动就必须走到底,也就是说直到前面是墙或者边界才能停。另外,如果你走......
  • centos7安装elasticsearch:7.9.3
    服务器安装elasticsearch:7.9.3一、安装前准备检查系统环境:确保CentOS7系统已经更新到最新版本。检查系统的硬件资源,确保满足Elasticsearch的安装和运行要求。安装OpenJDK:Elasticsearch需要Java环境,这里选择安装OpenJDK11。使用命令sudoyuminstalljava-11-open......
  • Elasticsearch简介
    前言什么是搜索引擎搜索引擎是指根据一定的策略、运用特定的计算机程序从互联网上采集信息,在对信息进行组织和处理后,为用户提供检索服务,将检索的相关信息展示给用户的系统。分类:全文索引搜索引擎采集ip段内的网页数据,扫描网页内容的每一个词,对其创建索引,指明词......
  • ElasticSearch 7.14 向已启用XPACK认证的集群增加新的节点
    一、环境现状描述:     目前的ElasticSearch集群仅有一个单一节点,且这个集群中已建立有索引,索引已包含业务文档数据(超过200G),该集群已经启用XPACK认证,现希望扩展这个集群,增加复制节点,且复制节点启动后,自动从主节点同步数据到新节点。     目前的ElasticSearch集群节点......
  • 基于HarmonyOS Next的医疗数据防泄漏与身份认证方案:Device Certificate Kit的深度应用
    本文旨在深入探讨华为鸿蒙HarmonyOSNext系统(截止目前API12)的技术细节,基于实际开发实践进行总结。主要作为技术分享与交流载体,难免错漏,欢迎各位同仁提出宝贵意见和问题,以便共同进步。本文为原创内容,任何形式的转载必须注明出处及原作者。在医疗信息化快速发展的今天,医疗......
  • HarmonyOS Next企业级设备认证解决方案:基于Device Certificate Kit的多层级身份验证
    本文旨在深入探讨华为鸿蒙HarmonyOSNext系统(截止目前API12)的技术细节,基于实际开发实践进行总结。主要作为技术分享与交流载体,难免错漏,欢迎各位同仁提出宝贵意见和问题,以便共同进步。本文为原创内容,任何形式的转载必须注明出处及原作者。在企业数字化转型的浪潮中,大量设......
  • 基于HarmonyOS Next的营销防薅羊毛设计:Device Certificate Kit的活动防护策略
    本文旨在深入探讨华为鸿蒙HarmonyOSNext系统(截止目前API12)的技术细节,基于实际开发实践进行总结。主要作为技术分享与交流载体,难免错漏,欢迎各位同仁提出宝贵意见和问题,以便共同进步。本文为原创内容,任何形式的转载必须注明出处及原作者。在电商和营销活动日益频繁的今天,......