首页 文章

Elasticsearch搜索查询问题

提问于
浏览
0

我无法从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:> {"query":{"bool":{"must":[{"match":{"status":"Active"}},{"match":{"is_published":真}},{"match":{"paid":真}},{"match":{"advertise_type":"Sell"}}]}},"sort":[{"updated_at":{"order":"desc"}}]}二○一八年十一月二十零日18时25分34秒0530:<{"took":3,"timed_out":假,"shards":{"total":1,"successful":1,"failed":0},"hits":{"total":0,"max_score":空,"hits":[]}} 2018年11月20日18时25分34秒0530:GET http://localhost:9200/_search [状态:200,请求:0.008s,查询:0.002s] 2018-11-20 18:25:34 0530:> {"query":{"bool":{"must":[{ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ {{{[{_ _ _ _ _ _ _ _ _ _ {"is_published":真}},{"match":{"paid":真}},{"match":{"advertise_type":"Sell"}}]}},"sort":[{"updated_at":{"order":"desc"}}]}二○一八年十一月二十零日18 :25:34 0530:<{"took":2,"timed_out":假,"_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":0,"max_score":空,"hits":[]}}

1 回答

  • 0

    如果我们不了解结构或者您想要通过查询实现什么,那么很难说出错了什么 .

    信息日志说明如下:

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

    这意味着,查询成功,服务器没有遇到任何错误 . 它只是没有找到任何匹配的文件到您的查询 .

    我'd recommend using a proper tool to first try your queries, for an example Kibanas'搜索探查器(https://www.elastic.co/guide/en/kibana/current/xpack-profiler.html) .

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

相关问题