ElasticSearch JS客户端search
我正在开始使用ElasticSearch,并且遇到麻烦(我不理解,因为它必须)如何search。
首先,我有这两个文件:
{ "took": 133 "timed_out": false "_shards": { "total": 5 "successful": 5 "failed": 0 } "hits": { "total": 2 "max_score": 1 "hits": [2] 0: { "_index": "app" "_type": "player" "_id": "AVcLCOgAi_gt2Fih02MK" "_score": 1 "_source": { "nickName": "sarasa" "birthDate": "1994-11-05T13:15:30.000Z" "state": "sarasa" "adminState": "sarasa" "id": "" "account": { "type": "yojuego" "id": "asasdfa" "password": "asd fasd" } } } 1: { "_index": "app" "_type": "player" "_id": "AVcQ7JNVi_gt2Fih02MN" "_score": 1 "_source": { "nickName": "facundo" "birthDate": "1994-11-05T13:15:30.000Z" "state": "verdura" "adminState": "sudo" "id": "" "account": { "type": "yojuego" "id": "facundo@facundo" "password": "pepe" } } } } } }
我想要在哪里account.id =“facundo @ facundo”和account.type =“yojuego”。 我正在这样做:
client.search({ index: 'app', type: 'player', query: { bool: { must: [ { term: { "account.id": 'facundo@facundo' } }, { term: { "account.type": 'yojuego' } } ], } } }, (error, response, status) => { if (error) { res.json(400, err); } else { res.json(200, response.hits.hits); } });
这个search是检索我已经进入索引的所有文件。 任何帮助?
谢谢!
PD:这是我如何创build索引和映射:
client.indices.create({ index: 'yojuego' }, (err, resp, respcode) => { if (!err) { client.indices.putMapping({ index: 'app', type: "player", body: { properties: { nickName: { type: "string" }, birthDate: { type: "string" }, state: { type: "string" }, adminState: { type: "string" }, account: { type: "nested", properties: { id: { type: "string" }, type: { type: "string" }, password: { type: "string" } } } } } }, (err, resp, respcode) => { res.json(200, resp); }); } });
确保该帐户是一个嵌套的字段,然后应用此查询,
{ "query": { "bool": { "must": [ { "nested": { "path": "account", "query": { "bool": { "must": [ { "match": { "account.id": "facundo@facundo" } }, { "match": { "account.type": "yojuego" } } ] } } } } ] } } }
- 对elasticsearch的GET请求中的'request_cache = true'不会创buildcaching
- 重复性工作订单系统的体系结构
- PostgreSQL与elasticsearch(保持同步) – nodeJS
- illegal_argument_exception请求包含无法识别的参数: – ElasticSearch索引创build
- 在多个expressjs路由中共享elasticsearch客户端
- illegal_argument_exception:没有为字段find映射
- 在Elasticsearch中使用nodejs创build索引时出错
- 如何在使用摩卡进行集成testing时处理elasticsearch的索引时间
- node.js:通过使用用户定义的id在elasticsearch中进行数据索引