1、match all
GET /_search
{
"query": {
"match_all": {}
}
}
搜索所有
2、match
GET /_search
{
"query": { "match": { "title": "my elasticsearch article" }}
}
根据搜索条件的值进行分词搜索
3、multi match
GET /test_index/_doc/_search
{
"query": {
"multi_match": {
"query": "test",
"fields": ["test_field", "test_field1"]
}
}
}
多个字段匹配 test
4、range query
GET /company/_doc/_search
{
"query": {
"range": {
"age": {
"gte": 30
}
}
}
}
范围搜索
5、term query
GET /test_index/_doc/_search
{
"query": {
"term": {
"test_field": "test hello"
}
}
}
term : 搜索的数据一定要和字段值完全匹配,
ES7.x 案例不能有空格,否则搜索不到
6、terms query
GET /_search
{
"query": { "terms": { "name": [ "tom", "jack", "nosql" ] }}
}
结果:
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 16,
"successful" : 16,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "company",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"address" : {
"country" : "china",
"province" : "guangdong",
"city" : "guangzhou"
},
"name" : "jack",
"age" : 27,
"join_date" : "2017-01-01"
}
},
{
"_index" : "company",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"address" : {
"country" : "china",
"province" : "jiangsu",
"city" : "nanjing"
},
"name" : "tom",
"age" : 30,
"join_date" : "2016-01-01"
}
},
{
"_index" : "company",
"_type" : "_doc",
"_id" : "5",
"_score" : 1.0,
"_source" : {
"address" : {
"country" : "china",
"province" : "zejiang",
"city" : "hangzhou"
},
"name" : "jack ma",
"age" : 58,
"join_date" : "2016-01-01"
}
}
]
}
}
terms : 搜索的数据一定要和搜索条件字段某个值匹配