简体   繁体   English

ElasticSearch和搜索文档不可预测

[英]ElasticSearch and searching documents unpredictable

Something very very strange is happening with ES JS Client. ES JS客户端正在发生非常非常奇怪的事情。 client.search() method seems to work properly, index and search data work correctly, but if a restart the elasticsearch.bat then the client stops working. client.search()方法似乎正常工作,索引和搜索数据正常工作,但是如果重新启动elasticsearch.bat,则客户端将停止工作。 I mean, client.search gives me 0 hits with same code. 我的意思是,client.search用相同的代码给了我0次匹配。 But if I search using any rest client, I find all documents availables in the index. 但是,如果我使用任何其他客户端进行搜索,则会在索引中找到所有可用的文档。

This is the mapping using this GET http://localhost:9200/yojuego/_mappings : 这是使用此GET http:// localhost:9200 / yojuego / _mappings的映射

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

Here is how I'm looking for the information from NodeJS: 这是我从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
    }
});

Related post: 相关文章:

I've received many answers, all worked properly at first, but then all of them stopped working 我收到了很多答案,起初都正常工作,但是后来所有人都停止了工作

Frameworks I'm using: 我正在使用的框架:

  • ElasticSearch 2.4.0 ElasticSearch 2.4.0
  • Node.js 6.3.0 Node.js 6.3.0
  • ElasticSearch.js 11.0.1 ElasticSearch.js 11.0.1

How did I install ElasticSearch? 我如何安装ElasticSearch? Just downloading it from ES WebSite, unzipping it and running elasticsearch.bat (I'm running on Windows 7) 只需从ES WebSite下载它,解压缩并运行elasticsearch.bat(我在Windows 7上运行)

Again, the problem is that ES stops working after ES service is resetted. 同样,问题在于重置ES服务后ES停止工作。 I'm pretty sure I'm doing something wrong, of course, but I can't realize where and what and why ES Service Search stop working sudeenly. 我当然可以肯定我做错了什么,但是我不知道ES Service Search在哪里,什么以及为什么突然停止工作。

When i say "stop working" I'm saying that the search method from ES js client retrieve 0 matches with the same query as it was using yesterday. 当我说“停止工作”时,我是说ES js客户端的搜索方法检索了0个与昨天使用的查询相同的查询。

I hope I explained it clearly. 我希望我能清楚地解释。 Thanks. 谢谢。

PD: PD:

Here is how I'm initializating es client: 这是初始化ES客户的方法:

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

Well, after too much effort I've found that the problem is in the way I was mapping the userId field. 好吧,经过过多的努力,我发现问题出在映射userId字段的方式上。 I was forggeting to mark it as not_analized , so here is how it looks like: 我忘记将其标记为not_analized ,所以它是这样的:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM