ElasticSearch和搜索文档不可预知
问题描述:
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 Indexing and Searching Not Working Correctly
- ElasticSearch JS Client Search by
- ElasticSearch JS query returns all document instead of filtered
我收到了很多答案,一切工作正常,在第一,但后来他们都停止了工作
框架我使用:
- 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'
});
答
好了,经过太多的努力,我发现这个问题是在我被映射userId字段的方式。我forggeting将其标记为not_analized
,所以这里是它的样子:
{
"yojuego": {
"mappings": {
"user": {
"properties": {
"password": {
"type": "string"
}
"type": {
"type": "string",
"index": "not_analyzed"
}
"userid": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
您可以编辑您的问题,包括你是如何设置和初始化你的JS代码的连接? –
完成!谢谢。 –
将'keepAlive:false'添加到客户端初始化时会发生什么? –