首页 文章

当卷曲请求执行时,Rails弹性搜索返回无命中

提问于
浏览
0

我有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)>

1 回答

  • 1

    试一下 :

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

相关问题