`

ElasticSearch DSL 示例

阅读更多
PUT /megacorp/employee/4
{
  "first_name": "Jay",
  "last_name": "Smith",
  "age": 27,
  "about": "I love rock music",
  "interests": [
    "sports",
    "music"
  ]
}

POST /megacorp/employee
{
  "first_name": "Jay",
  "last_name": "Smith",
  "age": 27,
  "about": "I love rock music",
  "interests": [
    "sports",
    "music"
  ]
}

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

GET /megacorp/employee/_search
{
  "query": {
    "match_phrase": {
      "about": "build cabinets"
    }
  }
}

GET /megacorp/employee/1

GET /megacorp/employee/1?pretty

GET /megacorp/employee/_search

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

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

GET /megacorp/employee/_search
{
  "query": {
    "filtered": {
      "filter": {
        "range": {
          "age": {
            "lt": 30
          }
        }
      },
      "query": {
        "match": {
          "last_name": "Zhong"
        }
      }
    }
  }
}

GET /megacorp/employee/_search
{
  "query": {
    "match": {
      "last_name": "Zhong"
    }
  },
  "highlight": {
    "fields": {
      "last_name": {}
    }
  }
}

GET /megacorp/employee/_search
{
  "aggs": {
    "all_interests": {
      "terms": {
        "field": "interests"
      }
    }
  }
}

GET /megacorp/employee/_search
{
  "query": {
    "match": {
      "last_name": "Zhong"
    }
  },
  "aggs": {
    "all_interests": {
      "terms": {
        "field": "interests"
      }
    }
  }
}

GET /megacorp/employee/_search
{
  "aggs": {
    "all_interests": {
      "terms": {
        "field": "interests"
      },
      "aggs": {
        "avg_age": {
          "avg": {
            "field": "age"
          }
        }
      }
    }
  }
}

GET /_cluster/health

PUT /blogs
{
  "settings": {
    "number_of_shards": 6,
    "number_of_replicas": 1
  }
}

PUT /blogs/_settings
{
  "number_of_replicas": 0
}

GET /megacorp/employee/_search?_source=age,interests

GET /megacorp/employee/1

GET /megacorp/employee/1/_source

PUT /website/blog/2?op_type=create
{
  "first_name": "Jay",
  "last_name": "Smith",
  "age": 27,
  "about": "I love rock music",
  "interests": [
    "sports",
    "music"
  ]
}

PUT /website/blog/122/_create
{
  "first_name": "Jay",
  "last_name": "Smith",
  "age": 27,
  "about": "I love rock music",
  "interests": [
    "sports",
    "music"
  ]
}

DELETE /website/blog/2

PUT /website/blog/2?version=13&version_type=external
{
  "title": "My first external blog entry",
  "text": "This is a piece of cake..."
}

GET /website/blog/2

POST /website/blog/2/_update
{
  "doc": {
    "tags": [
      "testing"
    ],
    "views": 0
  }
}

POST /_mget
{
  "docs": [
    {
      "_index": "website",
      "_type": "blog",
      "_id": 2
    },
    {
      "_index": "megacorp",
      "_type": "employee",
      "_id": 1,
      "_source": "age"
    }
  ]
}

POST /megacorp/employee/_mget
{
  "ids": [
    "2",
    "111"
  ]
}

POST /_bulk
{"delete":{"_index":"website","_type":"blog","_id":"223"}}
{"create":{"_index":"website","_type":"blog","_id":"223"}}
{"title":"My first blog post"}
{"index":{"_index":"website","_type":"blog"}}
{"title":"My second blog post"}
{"update":{"_index":"website","_type":"blog","_id":"223","_retry_on_conflict":3}}
{"doc":{"text":"My updated blog post"}}

POST /_bulk
{"create":{"_index":"website","_type":"blog","_id":"123"}}
{"title":"Cannot create - it already exists"}
{"index":{"_index":"website","_type":"blog","_id":"123"}}
{"title":"My first external blog entry","text":"This is a piece of cake..."}

POST /website/blog/_search

GET /megacorp/_search

GET /megacorp/employee/_mapping

GET /_analyze?analyzer=english
{
  "text": "Textes to analyze 5 32 遭受到"
}


GET megacorp/employee/_mapping

DELETE /megacorp2

PUT /megacorp2
{
  "mappings": {
    "employee": {
      "properties": {
        "about": {
          "type": "string",
          "analyzer": "english"
        },
        "age": {
          "type": "long"
        },
        "first_name": {
          "type": "string",
          "index": "not_analyzed"
        },
        "interests": {
          "type": "string"
        },
        "last_name": {
          "type": "string",
          "index": "no"
        }
      }
    }
  }
}


PUT /megacorp2/_mapping/employee
{
  "properties": {
    "about": {
      "type": "string",
      "analyzer": "english"
    },
    "age": {
      "type": "long"
    },
    "first_name": {
      "type": "string",
      "index": "not_analyzed"
    },
    "interests": {
      "type": "string"
    },
    "last_name": {
      "type": "string",
      "index": "no"
    }
  }
}

PUT /megacorp2/employee/1
{
  "first_name": "Jays 我",
  "last_name": "Smith",
  "age": 27,
  "about": "I love rock music 我饿么",
  "interests": [
    "sports",
    "music"
  ]
}

POST /megacorp2/employee
{
  "first_name": "Jays efe我",
  "last_name": "Smith",
  "age": 27,
  "about": "sfdf does you're I love rock music 我饿么",
  "interests": [
    "sports",
    "music"
  ]
}

PUT /megacorp/employee/66
{
  "first_name": [
    "sports",
    "music"
  ],
  "last_name": "Smith",
  "age": 27,
  "about": "I love rock music 我饿么",
  "interests": [
    "sports",
    "music"
  ]
}


GET /megacorp2/_search
{
  "query": {
    "match": {
      "last_name": "Smith"
    }
  }
}

POST megacorp/_search

PUT gb
{
  "tweet": {
    "properties": {
      "tweet": {
        "type": "string"
      },
      "user": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "gender": {
            "type": "string"
          },
          "age": {
            "type": "long"
          },
          "name": {
            "type": "object",
            "properties": {
              "full": {
                "type": "string"
              },
              "first": {
                "type": "string"
              },
              "last": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}


PUT gb/tweet/1
{
  "tweet": "Elasticsearch is very flexible",
  "user": {
    "id": "@johnsmith",
    "gender": "male",
    "age": 26,
    "name": {
      "full": "John Smith",
      "first": "John",
      "last": "Smith"
    }
  }
}

GET /gb/tweet/_search?pretty

GET /gb/tweet/_validate/query?explain
{
  "query": {
    "match": {
      "tweet": "really powerful"
    }
  }
}

GET /_search
{
  "query": {
    "filtered": {
      "query": {
        "match": {
          "email": "business opportunity"
        }
      },
      "filter": {
        "term": {
          "folder": "inbox"
        }
      }
    }
  }
}

GET /_search
{
  "query": {
    "filtered": {
      "filter": {
        "term": {
          "user_id": 1
        }
      }
    }
  },
  "sort": {
    "date": {
      "order": "desc"
    }
  }
}

GET gb/tweet/_search

GET gb/tweet/_search
{
  "query": {
    "filtered": {
      "query": {
        "match": {
          "tweet": "Elasticsearch is very flexible"
        }
      },
      "filter": {
        "term": {
          "user.id": "@johnsmith"
        }
      }
    }
  },
  "sort": [
    {
      "user.id": {
        "order": "desc"
      }
    },
    {
      "_score": {
        "order": "desc"
      }
    }
  ]
}

GET /gb/tweet/1/_explain
{
  "query": {
    "filtered": {
      "filter": {
        "term": {
          "user.id": "@johnsmith"
        }
      },
      "query": {
        "match": {
          "tweet": "Elasticsearch is very flexible"
        }
      }
    }
  }
}


GET /gb/tweet/1/_explain
{
  "query": {
    "filtered": {
      "filter": {
        "term": {
          "user.id": "@johnsmith"
        }
      },
      "query": {
        "match": {
          "tweet": "Elasticsearch"
        }
      }
    }
  }
}

GET /megacorp/_search?search_type=scan&scroll=1m
{
  "query": {
    "match_all": {}
  },
  "size": 1000
}


 

 

分享到:
评论

相关推荐

    ElasticSearch Java API 中文文档

    8. **查询DSL (Query DSL)**: 详细介绍了ElasticSearch的查询语言(Domain Specific Language),包括全量查询(Match All Query)、全文查询(Full Text Queries)、词项级查询(Term level queries)、复合查询...

    Elasticsearch实战与原理解析 源代码.zip

    此外,Elasticsearch的查询语言——Query DSL,也是学习的重点。这是一套JSON格式的查询语法,允许你构造复杂的查询条件,如匹配、范围、模糊、布尔等查询。源代码中可能包含各种查询示例,帮助你熟悉这种强大的查询...

    Elasticsearch示例数据 accounts.json

    一旦数据导入,我们可以利用 Elasticsearch 强大的查询语言——Query DSL 来进行复杂的数据检索。例如,我们可以搜索所有在 2020 年注册的账户: ```json { "query": { "range": { "registration_date": { "gte...

    bboss+es基本操作示例.zip

    **bboss+es基本操作示例** ...总之,bboss+es基本操作示例是学习和实践Elasticsearch与Java集成的优秀资源,通过这个示例,开发者可以快速掌握bboss框架下的DSL操作,为实际项目开发打下坚实基础。

    elasticsearch-dsl.cr:Elasticsearch的Crystal DSL

    总的来说,`elasticsearch-dsl.cr`是Crystal开发者与Elasticsearch交互的强大工具,它降低了Elasticsearch API的使用门槛,提高了代码质量,让开发工作更加高效和愉快。通过深入理解和熟练运用这个库,你将能够更好...

    elasticsearch JAVA使用手册

    Elasticsearch 5.0.1版本的Java API操作为开发者提供了具体操作的示例代码,这些代码示例能够帮助开发者更加高效地管理和优化Elasticsearch集群。 综上所述,Elasticsearch是一个功能强大的搜索引擎,它的Java API...

    一款基于SQL查询ES的Java工具包,支持SQL解析DSL,支持JDBC驱动,支持和Mybatis、Spring集成.zip

    标题中的“一款基于SQL查询ES的Java工具包”指的是一个Java库,专门设计用于通过SQL语句查询Elasticsearch(ES)数据存储。Elasticsearch是一个流行的开源搜索引擎和分析引擎,广泛应用于日志分析、实时分析等领域。...

    Elasticsearch API

    入门Elasticsearch时,首先应该熟悉Elasticsearch的领域特定语言(DSL),这是一种用于查询和操作数据的灵活查询语言。熟悉DSL并不需要你能够编写复杂的查询语句,但你应该了解Elasticsearch中有哪些功能,比如搜索...

    ElasticSearch的基本功能,Google的protobuf消息方法方式示例

    Elasticsearch(ES)是一款开源的、分布式的全文搜索引擎,它基于Lucene构建,设计目标是实现快速、可扩展且实时的数据搜索与分析。ES的主要功能包括文档存储、索引构建、搜索、聚合以及分析。 1. **文档存储**:在...

    elasticsearch_ruby:Elasticsearch Ruby 示例脚本

    **Elasticsearch Ruby 示例脚本**是专门为使用Ruby与Elasticsearch进行交互而设计的一系列示例代码。Elasticsearch是一种流行的开源全文搜索引擎,而Ruby是面向对象的编程语言,两者结合提供了强大的数据检索和分析...

    elasticsearch数据库下载、配置、使用案例PPT模板

    ### Elasticsearch数据库的下载、配置与使用案例 #### 一、Elasticsearch数据库的下载与安装 **1.1 下载与解压** - **下载Elasticsearch:** - **官方网站下载:** 访问Elasticsearch官方网站...

    elasticsearch java操作的api实例

    - **Query DSL**:Elasticsearch支持一种名为Query DSL的JSON风格查询语言。Java API中的`QueryBuilder`接口提供了一系列方法来构建这些查询。例如,我们可以使用`MatchQueryBuilder`进行全文本匹配,`...

    elasticsearch权威指南-中文

    4. **搜索与查询**:探讨Elasticsearch的全文检索能力,包括分析器、查询DSL语言、布尔运算符、评分机制等,以及如何构建复杂的查询语句。 5. **聚合分析**:讲解Elasticsearch的聚合功能,如何通过聚合数据进行...

    elasticsearch+django搜索框架

    5. 集成示例:创建一个`search`应用,定义一个`SearchDocument`模型,包含与Elasticsearch索引相关的字段。配置`settings.py`以连接Elasticsearch实例。在`models.py`中创建`SearchDocument`类,继承`DocType`,并...

    52.(leaflet篇)leaflet多边形空间查询(ElasticSearch技术实现).zip

    在Elasticsearch查询DSL(Domain Specific Language)中,这可能看起来像这样: ```json { "query": { "bool": { "filter": { "geo_shape": { "location": { "shape": { "type": "polygon", "coordinates":...

    Elasticsearch 技术解析与实战.zip

    前言 第1章 Elasticsearch入门 1 1.1 Elasticsearch是什么 1 1.1.1 Elasticsearch的历史 2 1.1.2 相关产品 3 1.2 全文搜索 3 1.2.1 Lucene介绍 4 1.2.2 Lucene倒排索引 4 1.3 基础知识 6 1.3.1 Elasticsearch术语及...

    elasticsearch RESTful搜索引擎-(java jest 使用[入门])

    **Elasticsearch RESTful搜索引擎与Java Jest库的入门教程** Elasticsearch是一个强大的分布式、开源的全文搜索引擎,它提供了一个可扩展的、近实时的搜索和分析引擎。RESTful API是Elasticsearch的核心特性,允许...

Global site tag (gtag.js) - Google Analytics