ruby-on-rails - curl 请求时,Rails Elasticsearch 不返回任何命中

标签 ruby-on-rails ruby-on-rails-3 elasticsearch

我有Rails,MongoId和Elasticsearch设置。从MongoDB到Elasticsearch,我有一条成功的大河,可以镜像和索引集合content中的所有内容。

使用Curl,直接到Elasticsearch,我可以成功地进行文本搜索:

{
    query: {
        match: {
            "content": "foo"
        }
    }
}

one@old-dash ~/river $ curl -XGET "localhost:9200/mongo_index/_search?pretty=true" -d @search.json

结果:
{
  "took": 35,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": 4.6738544,
    "hits": [
      {
        "_index": "mongo_index",
        "_type": "config_files",
        "_id": "54afe45ef7c61b3000009",
        "_score": 4.6738544,
        "_source": {
          "current": true,
          "device_id": "54afe167cf7c61b3000006",
          "updated_at": "2015-01-09T15:57:13.368Z",
          "retain": false,
          "name": "version",
          "checksum": "a55393f46e3d730f59de1ff4d3c378",
          "created_at": "2015-01-09T13:10:54.324Z",
          "skinny": false,
          "_id": "54afe453ccec61b3000009",
          "content": "Foo was here"
        }
      },
      {
        "_index": "mongo_index",
        "_type": "config_files",
        "_id": "54b00054f7c61b3000011",
        "_score": 4.6688538,
        "_source": {
          "current": false,
          "device_id": "54b00054cce1b3000010",
          "updated_at": "2015-01-09T16:23:14.543Z",
          "retain": false,
          "name": "my_awesome_config.conf",
          "checksum": "a55393f46e30f59de134ff4d3c378",
          "created_at": "2015-01-09T13:10:54.324Z",
          "skinny": false,
          "_id": "54b00054ccef7c63000011",
          "content": "foo was here 111"
        }
      }
    ]
  }
}

但是在Rails控制台中,我没有任何点击:
[3] pry(main)> bob = ConfigTextSearch.search query: { match:  { content: "foo" } } 
=> #<Elasticsearch::Model::Response::Response:0x007f0ea72a75d0
 @klass=[PROXY] ConfigTextSearch,
 @search=
  #<Elasticsearch::Model::Searching::SearchRequest:0x007f0ea72a76c0
   @definition=
    {:index=>"config_text_searches",
     :type=>"config_text_search",
     :body=>{:query=>{:match=>{:content=>"foo"}}}},
   @klass=[PROXY] ConfigTextSearch,
   @options={}>>
[4] pry(main)> bob.results.total
=> 0
[5] pry(main)>

关于我在做什么错的任何想法吗?

UPDATE :来自建议的输出,但仍然没有成功:
[14] pry(main)> query_string = { query: { match:  { content: "foo" } } }.to_json
=> "{\"query\":{\"match\":{\"content\":\"foo\"}}}"
[15] pry(main)> bob = ConfigTextSearch.search query_string
=> #<Elasticsearch::Model::Response::Response:0x007f0ea7505bb0
 @klass=[PROXY] ConfigTextSearch,
 @search=
  #<Elasticsearch::Model::Searching::SearchRequest:0x007f0ea7505d18
   @definition=
    {:index=>"config_text_searches",
     :type=>"config_text_search",
     :body=>"{\"query\":{\"match\":{\"content\":\"foo\"}}}"},
   @klass=[PROXY] ConfigTextSearch,
   @options={}>>
[16] pry(main)> bob.results.total
=> 0
[17] pry(main)> 

最佳答案

试一下 :

  query_string = { query: { match:  { content: "foo" } } }.to_json
  bob = ConfigTextSearch.search query_string

关于ruby-on-rails - curl 请求时,Rails Elasticsearch 不返回任何命中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27930919/

相关文章:

ruby-on-rails - 未定义的方法 `simple_form_for'

html - 如何将文本环绕在局部

ruby-on-rails - 当点击由 "link_to"生成的链接时,Rails 3 如何决定使用哪个 HTTP 动词?

amazon-web-services - Cloudwatch 日志流式传输到 ElasticSearch AWS

elasticsearch - 在ElasticSearch中获取与前缀查询匹配的术语

elasticsearch - 如何在 Elasticsearch 聚合中使用分页(大小和来源)?

jquery - 使用远程提交 form_for 后刷新部分内容 : true

mysql - 通过加入的数据库显示用户全名

ruby-on-rails - rails : "BCrypt::Errors::InvalidHash" when trying to sign in

ruby-on-rails - 如何在Rails的 “content_tag”属性中使用HTML实体?