新手问题 使用 ElasticsSearch 出现 404 的问题

dccmmtop · August 06, 2017 · Last by pathbox replied at August 06, 2017 · 3770 hits
def wechat_query(q)
      Rails.logger.info("========= #{q}")
      search_modules = [Topic]
      search_params = {
        query: {
          simple_query_string: {
            query: q,
            default_operator: 'OR',
            minimum_should_match: '60%',
            fields: %w(title body name tags)
          }
        },
        highlight: {
          pre_tags: ['[h]'],
          post_tags: ['[/h]'],
          fields: { title: {}, body: {}, name: {}, tags: {} }
        }
      }
      Elasticsearch::Model.search(search_params, search_modules)
    end

    def user_interest_query(query)
      items = []
      query.split(',').each do |q|
        qs = wechat_query(q).records
        items = items | qs
      end
      items
    end  

当调用 user_interest_query(query) 出现 出现的问题如下: Transport::Transport::Errors::NotFound: [404] {"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"topics","index_uuid":"na","index":"topics"}],"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"topics","index_uuid":"na","index":"topics"},"status":404}

需要为 elasticsearch 配置什么吗

错误已经告诉你了,没有找到索引

Reply to pathbox

如何添加索引呢?

Reply to dccmmtop

好吧。。。先把 elasticsearch 的文档看完或者看你使用的 elasticsearch 的 gem 文档

You need to Sign in before reply, if you don't have an account, please Sign up first.