2016-09-19 41 views
0

ES JS Client發生了一件非常奇怪的事情。 client.search()方法似乎正常工作,索引和搜索數據正常工作,但如果重新啓動elasticsearch.bat,則客戶端停止工作。我的意思是,client.search給了我0次相同的代碼。但是,如果我使用任何其他客戶端進行搜索,我會在索引中找到所有可用的文檔。ElasticSearch和搜索文檔不可預知

這是映射使用該GET http://localhost:9200/yojuego/_mappings

{ 
    "yojuego": { 
     "mappings": { 
      "user": { 
      "properties": { 
       "password": { 
        "type": "string" 
        } 
       "type": { 
        "type": "string" 
        } 
       "userid": { 
        "type": "string" 
        } 
       } 
      } 
     } 
    } 
} 

這裏是我要找的NodeJS從信息:

this.client.search({ 
    index: "yojuego", 
    type: "user", 
    body: { 
     "query": { 
      "filtered": { 
       "filter": { 
        "bool": { 
         "must": [ 
          { "term": { "userid": criteria } }, 
          { "term": { "type": "yojuego" } } 
         ] 
        } 
       } 
      } 
     } 
    } 
}, (error, response, status) => { 
    if (error) { 
     //I have no error 
    } 
    else { 
     //Here is where I have 0 hits in response.hits.hits 
    } 
}); 

相關崗位:

我收到了很多答案,一切工作正常,在第一,但後來他們都停止了工作

框架我使用:

  • ElasticSearch 2.4。 0
  • Node.js 6.3.0
  • ElasticSearch.js 11.0.1

我是如何安裝ElasticSearch的? 只需從ES網站下載,解壓縮並運行elasticsearch.bat(我在Windows 7上運行)

問題是ES服務重置後,ES停止工作。 我很確定我做錯了什麼,當然,但我不知道ES服務搜索在哪裏以及爲什麼停止工作。

當我說「停止工作」時,我說從ES js客戶端的搜索方法檢索0匹配使用與昨天使用的查詢相同的查詢。

我希望我解釋清楚。 謝謝。

PD:

這裏是如何我initializating ES客戶端:

var es = require('elasticsearch'); 
var client = new es.Client({ 
    host: 'http://localhost:9200', 
    log: 'info' 
}); 
+0

您可以編輯您的問題,包括你是如何設置和初始化你的JS代碼的連接? –

+0

完成!謝謝。 –

+0

將'keepAlive:false'添加到客戶端初始化時會發生什麼? –

回答

0

好了,經過太多的努力,我發現這個問題是在我被映射userId字段的方式。我forggeting將其標記爲not_analized,所以這裏是它的樣子:

{ 
    "yojuego": { 
     "mappings": { 
      "user": { 
      "properties": { 
       "password": { 
        "type": "string" 
        } 
       "type": { 
        "type": "string", 
        "index": "not_analyzed" 
        } 
       "userid": { 
        "type": "string", 
        "index": "not_analyzed" 
        } 
       } 
      } 
     } 
    } 
}