您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
elasticSearch查询字符串查询(query_string)
发布时间:2021-09-06 21:42:21编辑:雪饮阅读()
查询字符串查询
此查询使用查询解析器和query_string关键字。 例如,
请求体:
{
"query":{
"query_string":{
"query":"Central School"
}
}
}
响应体:
{
"took": 47,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": 1.1631508,
"hits": [
{
"_index": "schools",
"_type": "school",
"_id": "1",
"_score": 1.1631508,
"_source": {
"name": "Central School",
"description": "CBSE Affiliation",
"street": "Nagan",
"city": "paprola",
"state": "HP",
"zip": "176115",
"location": [
31.8955385,
76.8380405
],
"fees": 2000,
"tags": [
"Senior Secondary",
"beautiful campus"
],
"rating": "3.5"
}
},
{
"_index": "schools",
"_type": "school",
"_id": "3",
"_score": 1.1631508,
"_source": {
"name": "Central School",
"description": "ICSE",
"street": "West End",
"city": "pune",
"state": "UP",
"zip": "250002",
"location": [
28.9926174,
77.692485
],
"fees": 3500,
"tags": [
"fully computerized"
],
"rating": "4.5"
}
},
{
"_index": "schools",
"_type": "school",
"_id": "2",
"_score": 0.23883039,
"_source": {
"name": "Saint Paul School",
"description": "ICSE Afiliation",
"street": "Dawarka",
"city": "Delhi",
"state": "Delhi",
"zip": "110075",
"location": [
28.5733056,
77.0122136
],
"fees": 5000,
"tags": [
"Good Faculty",
"Great Sports"
],
"rating": "4.5"
}
}
]
}
}
这里可以看到query的值是一个字符串而并不是一个单词。
那么实际上不要被这里误解了,并不是说仅查询字符串查询可以查询字符串,而普通匹配查询就只能查询单词。
再来看看普通的匹配查询
请求体:
{
"query":{
"match" : {
"name":"Central School"
}
}
}
响应体:
{
"took": 67,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": 1.1631508,
"hits": [
{
"_index": "schools",
"_type": "school",
"_id": "1",
"_score": 1.1631508,
"_source": {
"name": "Central School",
"description": "CBSE Affiliation",
"street": "Nagan",
"city": "paprola",
"state": "HP",
"zip": "176115",
"location": [
31.8955385,
76.8380405
],
"fees": 2000,
"tags": [
"Senior Secondary",
"beautiful campus"
],
"rating": "3.5"
}
},
{
"_index": "schools",
"_type": "school",
"_id": "3",
"_score": 1.1631508,
"_source": {
"name": "Central School",
"description": "ICSE",
"street": "West End",
"city": "pune",
"state": "UP",
"zip": "250002",
"location": [
28.9926174,
77.692485
],
"fees": 3500,
"tags": [
"fully computerized"
],
"rating": "4.5"
}
},
{
"_index": "schools",
"_type": "school",
"_id": "2",
"_score": 0.23883039,
"_source": {
"name": "Saint Paul School",
"description": "ICSE Afiliation",
"street": "Dawarka",
"city": "Delhi",
"state": "Delhi",
"zip": "110075",
"location": [
28.5733056,
77.0122136
],
"fees": 5000,
"tags": [
"Good Faculty",
"Great Sports"
],
"rating": "4.5"
}
}
]
}
}
可以看到普通匹配查询也能查多个单词,就我觉得上面无论那种查询多个单词被视为一个整体(包含空格)。
那么实际上查询字符串查询与上篇中的multi_match查询有点类似。
查询字符串支持Lucene语法来解释文本,其中为 multi_match只是尝试将给定的“文本”与列出的字段的索引值进行匹配。
关键字词:elasticSearch,查询字符串查询,query_string
相关文章
- elasticSearch的multi_match查询(指定多个字段查询)
- elasticSearch匹配查询
- elasticSearch集群健康状态变黄yellow及Unassigned问
- elasticSearch查询DSL-匹配所有查询
- elasticSearch节点hot_threads
- elasticSearch集群api-节点统计
- elasticSearch群集更新设置api参数flat_settings的使
- elasticSearch群集更新设置(transient)
- elasticSearch集群获取设置api与群集更新设置(persist
- elasticSearch分片(主分片、副本分片)与节点的关系