繁体   English   中英

Elasticsearch搜索查询问题

[英]Elasticsearch search query issue

我无法从elasticsearch服务器获得匹配。 我的代码-

client = Elasticsearch::Client.new log: true
client.indices.refresh index: 'property_index'
# search_results = client.search(body: { query: { multi_match: { query: search_params, fields: ['street_address', 'suburb'] } } })
match_query = [
  { match: { status: 'Active'} }
]
match_query << { match: { is_published: true} }
match_query << { match: { paid: true} }
match_query << { match: { suburb: params[:suburb].to_s} } if !params[:suburb].blank?
match_query << { match: { advertise_type: params[:advertise_type].to_s} } if !params[:advertise_type].blank?
match_query << { match: { state: params[:state].to_s} } if !params[:state].blank?
match_query << { match: { postal_code: params[:postal_code]} } if !params[:postal_code].blank?
response = client.search(body: {
                                  query: { bool: { must: match_query }},
                                  sort: [
                                    { updated_at: { order: "desc" }}
                                  ]
                              }, from: params[:offset], size: params[:limit])

all_records = client.search(body: {
                query: { bool: { must: match_query }},
                sort: [
                  { updated_at: { order: "desc" }}
                ]
              })

这是我得到的响应输出-

GET http://localhost:9200/_search?from=0&size=10 [status:200, request:0.010s, query:0.003s]

2018-11-20 18:25:34 +0530:> {“查询”:{“布尔”:{“必须”:[{“匹配”:{“状态”:“有效”}}},{“匹配” :{ “is_published”:真正}},{ “匹配”:{ “有偿”:真正}},{ “匹配”:{ “advertise_type”: “卖出”}}]}}, “排序”:[{” Updated_at“:{” order“:” desc“}}]} 2018-11-20 18:25:34 +0530:<{” took“:3,” timed_out“:false,” _ shards“:{” total“ :1,“成功”:1,“失败”:0},“点击”:{“总计”:0,“ max_score”:null,“点击”:[]}} 2018-11-20 18:25: 34 +0530:GET http:// localhost:9200 / _search [状态:200,请求:0.008s,查询:0.002s] 2018-11-20 18:25:34 +0530:> {“查询”:{“布尔 “:{” 必须 “:[{” 匹配 “:{” 地位 “:” 主动 “}},{” 匹配 “:{” is_published “:真正}},{” 匹配 “:{” 有偿“:真}},{“ match”:{“ advertise_type”:“出售”}}}}},“ sort”:[{“ updated_at”:{“ order”:“ desc”}}]}} 2018-11-20 18 :25:34 +0530:<{“ took”:2,“ timed_out”:false,“ _ shards”:{“ total”:1,“ successful”:1,“ failed”:0},“ hits”:{ “总”:0, “MAX_SCORE”:空, “命中”:[]}}

如果我们不了解结构或您要通过查询实现的目标,很难分辨出问题所在。

信息日志显示以下内容:

timed_out:false
Shards:
 total:1 
 successful: 1
 failed:0
Hits: 
 total: 0 

这意味着查询成功,并且服务器未遇到任何错误。 它只是找不到与您的查询匹配的文档。

我建议您使用合适的工具首先尝试您的查询,例如Kibanas的搜索分析器( https://www.elastic.co/guide/en/kibana/current/xpack-profiler.html )。

这将向您显示有关查询的信息,一旦找到合适的查询,便可以将其集成到代码中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM