Elasticsearch基于RequsetBody的一些查询API示例
)
1.基于RequestBody进行查询
#查询title中包含Last或者Christmas的数据
POST movies/_search
{
"profile": "true",
"query": {
"match": {
"title": "Last Christmas"
}
}
}
#查询title中同时包含Last和Christmas的数据
POST movies/_search
{
"profile": "true",
"query": {
"match": {
"title": {
"query": "Last Christmas",
"operator": "and"
}
}
}
}
#查询title中包含短语one love的数据
POST movies/_search
{
"profile": "true",
"query": {
"match_phrase": {
"title": {
"query": "one love"
}
}
}
}
#查询title中包含短语one love的数据,允许中间有一个其他的单词
POST movies/_search
{
"profile": "true",
"query": {
"match_phrase": {
"title": {
"query": "one love",
"slop": 1
}
}
}
}
2.Query String
1.测试数据准备
PUT /users/_doc/1
{
"name":"Wang Zhongsan",
"about":"java,golang,node,swift,eleasticsearch"
}
PUT /users/_doc/2
{
"name":"Lv Zhongsan",
"about":"Hadoop"
}
2.单字段查询
#Query String
POST users/_search
{
"query": {
"query_string": {
"default_field": "name",
"query": "wang AND zhongsan"
}
}
}
3.多字段查询
POST users/_search
{
"profile": "true",
"query": {
"query_string": {
"query": "(wang AND zhongsan) OR (java AND eleasticsearch)",
"fields": ["name","about"]
}}
}
3.Simple query String
#Simple query String,默认的operator是OR
#查询name中包含lv或者zhongsan的数据
POST users/_search
{
"profile": "true",
"query": {
"simple_query_string": {
"query": "lv zhongsan",
"fields": ["name"]
}
}
}
#查询name中同时包含lv和zhongsan的数据 AND
POST users/_search
{
"profile": "true",
"query": {
"simple_query_string": {
"query": "lv zhongsan",
"fields": ["name"],
"default_operator": "AND"
}
}
}