PUT test_search_index
{
"settings": {
"number_of_shards": 5,
"number_of_replicas": 1
}
}
POST test_search_index/doc/_bulk
{"index":{"_id":"1"}}
{"username":"alfred way","job":"java engineer","age":18,"birth":"1992-01-02","isMarried":false}
{"index":{"_id":"2"}}
{"username":"alfred","job":"java senior engineer and java specialist","age":28,"birth":"1980-05-07","isMarried":true}
{"index":{"_id":"3"}}
{"username":"lee","job":"java and ruby engineer","age":22,"birth":"1985-08-07","isMarried":false}
{"index":{"_id":"4"}}
{"username":"alfred junior way","job":"ruby engineer","age":23,"birth":"1989-08-07","isMarried":false}
# match
GET test_search_index/doc/_search
{
"query": {
"match": {
"username": "alfred way"
}
}
}
GET test_search_index/doc/_search
{
"profile": "true",
"query": {
"match": {
"username": "alfred way"
}
}
}
GET test_search_index/doc/_search
{
"query": {
"match": {
"username": {
"query": "alfred way",
"operator": "and"
}
}
}
}
GET test_search_index/_search
{
"query": {
"match": {
"username": {
"query": "alfred way",
"minimum_should_match": 2
}
}
}
}
GET test_search_index/_search
{
"query": {
"match": {
"job": {
"query": "java ruby engineer",
"minimum_should_match": 3
}
}
}
}
# match_phrase
GET test_search_index/_search
{
"query": {
"match_phrase": {
"job": "java engineer"
}
}
}
GET test_search_index/_search
{
"query": {
"match_phrase": {
"job": {
"query": "java engineer",
"slop": 2
}
}
}
}
# query string
GET test_search_index/_search
{
"query": {
"query_string": {
"default_field": "username",
"query": "alfred AND way"
}
}
}
GET test_search_index/_search
{
"query": {
"query_string": {
"fields": ["username","job"],
"query": "alfred OR (java AND ruby)"
}
}
}
# simple query string
GET test_search_index/_search
{
"query": {
"simple_query_string": {
"query": "alfred +way",
"fields": ["username"]
}
}
}
# term query
GET test_search_index/_search
{
"query": {
"term": {
"username": "alfred"
}
}
}
GET test_search_index/_search
{
"query": {
"term": {
"username": "alfred way"
}
}
}
GET test_search_index/_search
{
"query": {
"terms": {
"username": [
"alfred",
"way"
]
}
}
}
# range query
GET test_search_index/_search
{
"query": {
"range": {
"age": {
"gte": 10,
"lte": 30
}
}
}
}
GET test_search_index/_search
{
"query": {
"range": {
"birth": {
"gte": "1990-01-01"
}
}
}
}
GET test_search_index/_search
{
"query": {
"range": {
"birth": {
"gte": "now-30y"
}
}
}
}
GET test_search_index/_search
{
"query": {
"range": {
"birth": {
"gte": "2010||-20y"
}
}
}
}
# constant score
GET test_search_index/_search
{
"query": {
"constant_score": {
"filter": {
"match": {
"username": "alfred"
}
}
}
}
}
# bool query
GET test_search_index/_search
{
"query": {
"bool": {
"filter": [
{
"term": {
"username": "alfred"
}
}
]
}
}
}
GET test_search_index/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"username": "alfred"
}
},
{
"match": {
"job": "specialist"
}
}
]
}
}
}
GET test_search_index/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"job": "java"
}
}
],
"must_not": [
{
"match": {
"job": "ruby"
}
}
]
}
}
}
GET test_search_index/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"username": "junior"
}
},
{
"match": {
"job": "ruby"
}
}
]
}
}
}
GET test_search_index/_search
{
"query": {
"bool": {
"should": [
{"term": {"job": "java"}},
{"term": {"job": "ruby"}},
{"term": {"job": "specialist"}}
],
"minimum_should_match": 2
}
}
}
# must与should一起时,must为主,should加分
GET test_search_index/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"username": "alfred"
}
}
],
"should": [
{
"term": {
"job": "ruby"
}
}
]
}
}
}
# count api
GET test_search_index/_count
{
"query": {
"match": {
"username": "alfred"
}
}
}
# source_filter
# 方式一
GET test_search_index/_search?_source=username
# 方式二
GET test_search_index/_search
{
"_source": false
}
GET test_search_index/_search
{
"_source": ["username", "age"]
}
GET test_search_index/_search
{
"_source": {
"includes": "*i*",
"excludes": "birth"
}
}
Elasticsearch Query DSL
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 引言 虽然之前做过 elasticsearch 的项目,但是没有对整个项目的知识点进行过系统的整理。这次趁着对 e...
- 基本语法 示例 组合搜索多个条件 定位不合法的搜索以及原因 filter与query的对比 filter与quer...
- 1、Query DSL基础语法 (1)查询全部index下的全部type的全部document (2)查询test...
- 双十一来临,大家应该要对所有索引都做做健康检查了,由于最近压力上不去,所以盯上了Query Cache,由于之前Q...