Elasticsearch创建联接字段(Node.js) [英] Elasticsearch create join field (Nodejs)
问题描述
我有以下文档:
导出类CustomerServiceResultType {id:字符串;正文:{customerRelation:string};}出口类别CustomerType {id:字符串;正文:{name:string};}
我希望 CustomerServiceResultType
与 CustomerType
具有以下字段的关系: customerRelation
.
这是我的映射:
等待this.elasticsearchService.indices.putMapping({"index":"db","type":"CustomerServiceResultType",身体":{属性":{"customerRelation":{"type":"join",关系":{"CustomerServiceResultType":"CustomerType"}}}}});
这是我得到的错误:
[嵌套] 421512-11/21/2020,6:40:42 PM [ExceptionsHandler]非法参数异常+ 96414msResponseError:非法参数_异常
没有关于此错误的详细信息...
谢谢
您的请求本身没有问题-我认为它只需要一个额外的选项: include_type_name:true
.>
它是 <代码在Node.js中默认为> undefined ,但此处.
这应该可以解决问题:
等待client.indices.putMapping({include_type_name:是,索引:"db",类型:"CustomerServiceResultType",身体 : {特性: {客户关系: {类型:"join",关系:{CustomerServiceResultType:"CustomerType"}}}}});
键入的索引将在8.x中删除,因此最好的方法实际上是:
等待client.indices.putMapping({索引:"db",身体 : {特性: {客户关系: {类型:"join",关系:{CustomerServiceResultType:"CustomerType"}}}}});
顺便说一句:您的打字稿类型在这里并没有真正发挥作用,因为ES是仅JSON的接口,并且ES弃用了 type
方面,但这两个概念相距甚远.>
I have the following docs:
export class CustomerServiceResultType{
id: string;
body:{customerRelation: string};
}
export class CustomerType{
id: string;
body:{name: string};
}
I want CustomerServiceResultType
to have a relation to CustomerType
with the field: customerRelation
.
this is my mapping:
await this.elasticsearchService.indices.putMapping({
"index": "db",
"type": "CustomerServiceResultType",
"body" : {
"properties": {
"customerRelation": {
"type": "join",
"relations": {
"CustomerServiceResultType": "CustomerType"
}
}
}
}
});
This is the error I get:
[Nest] 421512 - 11/21/2020, 6:40:42 PM [ExceptionsHandler] illegal_argument_exception +96414ms
ResponseError: illegal_argument_exception
There are no details about this error...
Thanks
There's nothing wrong with your request per-se -- I think it just requires one extra option: include_type_name: true
.
It's undefined
by default in nodejs but is required in ES 7.x on the server side. More reasoning behind this is here.
So this should do the trick:
await client.indices.putMapping({
include_type_name: true,
index: "db",
type: "CustomerServiceResultType",
body : {
properties: {
customerRelation: {
type: "join",
relations: {
CustomerServiceResultType: "CustomerType"
}
}
}
}
});
Typed indexes will be removed in 8.x so the best approach would actually be:
await client.indices.putMapping({
index: "db",
body : {
properties: {
customerRelation: {
type: "join",
relations: {
CustomerServiceResultType: "CustomerType"
}
}
}
}
});
BTW: your typescript types don't really play a role here because ES is a JSON-only interface and while there's the deprecated type
aspect to ES, the two concepts are very distant.
这篇关于Elasticsearch创建联接字段(Node.js)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!