zoukankan      html  css  js  c++  java
  • elasticsearch基本使用

    添加

    PUT /megacorp/employee/1
    {
        "first_name" : "John",
        "last_name" :  "Smith",
        "age" :        25,
        "about" :      "I love to go rock climbing",
        "interests": [ "sports", "music" ]
    }
    

    获取

    GET /megacorp/employee/1
    

    简单搜索

    GET /megacorp/employee/_search
    

    简单条件搜索

    GET /megacorp/employee/_search?q=last_name:Smith
    

    条件搜索

    GET /megacorp/employee/_search
    {
        "query" : {
            "match" : {
                "last_name" : "Smith"
            }
        }
    }
    

    更复杂的搜索

    GET /megacorp/employee/_search
    {
        "query" : {
            "bool": {
                "must": {
                    "match" : {
                        "last_name" : "smith" 
                    }
                },
                "filter": {
                    "range" : {
                        "age" : { "gt" : 10 } 
                    }
                }
            }
        }
    }
    

    全文搜索

    GET /megacorp/employee/_search
    {
        "query" : {
            "match" : {
                "about" : "rock climbing"
            }
        }
    }
    

    再添加一个

    PUT /megacorp/employee/2
    {
        "first_name" :  "张",
        "last_name" :   "三",
        "age" :         24,
        "about":        "一个PHP程序员,热爱编程,热爱生活,充满激情。",
        "interests":  [ "英雄联盟" ]
    }
    

    高亮搜索

    GET /megacorp/employee/_search
    {
        "query" : {
            "match_phrase" : {
                "about" : "rock climbing"
            }
        },
        "highlight": {
            "fields" : {
                "about" : {}
            }
        }
    }
    
    {
      "took": 114,
      "timed_out": false,
      "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
      },
      "hits": {
        "total": 1,
        "max_score": 0.5753642,
        "hits": [
          {
            "_index": "megacorp",
            "_type": "employee",
            "_id": "1",
            "_score": 0.5753642,
            "_source": {
              "first_name": "John",
              "last_name": "Smith",
              "age": 25,
              "about": "I love to go rock climbing",
              "interests": [
                "sports",
                "music"
              ]
            },
            "highlight": {
              "about": [
                "I love to go <em>rock</em> <em>climbing</em>"
              ]
            }
          }
        ]
      }
    }
    

    获取数量

    GET /megacorp/employee/_count
    {
        "query": {
            "match" : {
                "last_name" : "Smith"
            }
        }
    }
    
  • 相关阅读:
    再谈iOS 7的手势滑动返回功能
    CGContextRef用法
    UIView的layoutSubviews和drawRect方法何时调用
    layoutSubviews何时调用的问题
    iOS应用开发最佳实践:编写高质量的Objective-C代码
    WWDC2014之App Extensions学习笔记
    定制iOS 7中的导航栏和状态栏
    从客户端中检测到有潜在危险的 Request.Form 值
    async and await 简单的入门
    C# Dictionary学习
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/9272998.html
Copyright © 2011-2022 走看看