世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
问:simple_query_string有什么特点? 答:  问:simple_query_string如何使用? 答:
# simple_query_string
PUT /simple_query_string_test
{
"mappings": {
"properties": {
"name": {"type": "text"}
}
}
}
# 索引
POST /simple_query_string_test/_doc/1
{
"name": "hello good me"
}
# 索引
POST /simple_query_string_test/_doc/2
{
"name": "world in the sky"
}
# 搜索
GET /simple_query_string_test/_search
{
"query": {
"simple_query_string": {
"fields": ["name"],
"query" : "(world sky) | (hello good)"
}
}
}
# 结果
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 1.4723402,
"hits" : [
{
"_index" : "simple_query_string_test",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.4723402,
"_source" : {
"name" : "hello good me"
}
},
{
"_index" : "simple_query_string_test",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.3097506,
"_source" : {
"name" : "world in the sky"
}
}
]
}
}
# 搜索
GET /simple_query_string_test/_search
{
"query": {
"simple_query_string": {
"fields": ["name"],
"query" : "(world sky) + (hello good)"
}
}
}
# 结果
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 0,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
}
}
|