简体   繁体   English

Elasticsearch搜索查询问题

[英]Elasticsearch search query issue

I am not being able to get the hits from the elasticsearch server. 我无法从elasticsearch服务器获得匹配。 My code- 我的代码-

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" }}
                ]
              })

This is the response output that i am getting- 这是我得到的响应输出-

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

2018-11-20 18:25:34 +0530: > {"query":{"bool":{"must":[{"match":{"status":"Active"}},{"match":{"is_published":true}},{"match":{"paid":true}},{"match":{"advertise_type":"Sell"}}]}},"sort":[{"updated_at":{"order":"desc"}}]} 2018-11-20 18:25:34 +0530: < {"took":3,"timed_out":false,"_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}} 2018-11-20 18:25:34 +0530: GET http://localhost:9200/_search [status:200, request:0.008s, query:0.002s] 2018-11-20 18:25:34 +0530: > {"query":{"bool":{"must":[{"match":{"status":"Active"}},{"match":{"is_published":true}},{"match":{"paid":true}},{"match":{"advertise_type":"Sell"}}]}},"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":{"total":0,"max_score":null,"hits":[]}} 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”:空, “命中”:[]}}

It's kind of difficult to tell what's wrong if we do not know about the structure or what you're trying to achieve with the query. 如果我们不了解结构或您要通过查询实现的目标,很难分辨出问题所在。

The information log says the following: 信息日志显示以下内容:

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

Which means, that the query was successful, and the server encountered no errors. 这意味着查询成功,并且服务器未遇到任何错误。 It just did not find any matching documents to your query. 它只是找不到与您的查询匹配的文档。

I'd recommend using a proper tool to first try your queries, for an example Kibanas' search profiler ( https://www.elastic.co/guide/en/kibana/current/xpack-profiler.html ). 我建议您使用合适的工具首先尝试您的查询,例如Kibanas的搜索分析器( https://www.elastic.co/guide/en/kibana/current/xpack-profiler.html )。

This shows you information about your query, once you find your query suitable, you can integrate it into your code. 这将向您显示有关查询的信息,一旦找到合适的查询,便可以将其集成到代码中。

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

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