gpt4 book ai didi

node.js - ElasticSearch JS 客户端搜索依据

转载 作者:太空宇宙 更新时间:2023-11-03 22:12:04 26 4
gpt4 key购买 nike

我正在开始使用 ElasticSearch,但我遇到了如何搜索的麻烦(我不明白,因为它必须如此)。

首先,我有这两个文件:

{
"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);
}
});

此搜索正在检索我在索引中拥有的所有文档。有什么帮助吗?

谢谢!

PD:这是我创建索引和映射的方法:

  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"
}
}
]
}
}
}
}
]
}
}
}

关于node.js - ElasticSearch JS 客户端搜索依据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39420536/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com