gpt4 book ai didi

arrays - 过滤对象数组

转载 作者:行者123 更新时间:2023-12-02 22:48:56 25 4
gpt4 key购买 nike

在 elasticsearch 中,我们有一个包含对象数组的类型。当尝试从 Kibana 访问时,我在访问时遇到一些不一致

这是我的映射的摘录,

{
"myIndex-2017.08.22": {
"mappings": {
"typeA": {
"properties": {
.
.
.
"Collection": {
"properties": {
.
.
.
"FileType": {
"type": "text"
}
}
}
}
}
}
}
}

在这里我可以在集合中有多个对象,即将它作为一个数组进行索引。当我也尝试使用一种文件类型(例如 FileType: DOCX)进行查询时,我也会得到一些文件类型为 HTML 的记录。

当深入观察时,我发现这是因为某些记录具有两个集合元素,一个是 FileType:DOCX,一个是 FileType:HTML。

为什么过滤会这样工作?有没有其他方法可以过滤并仅获取 FileType: DOCX 而不显示 FileType: HTML。

我正在运行 ES 5.3。

最佳答案

Elasticsearch 开箱即用地展平数组字段,因此

{
"files" : [
{
"name" : "name1",
"fileType" : "doc"
},
{
"name" : "name2",
"fileType" : "html"
}
]}

变成:

{
"files.name" : [ "name1", "name2" ],
"files.fileType" : [ "doc", "html" ]
}

如果你想在这个数组中搜索对象本身,你必须使用 nested datatype在集合的映射中:

{
"myIndex-2017.08.22": {
"mappings": {
"typeA": {
"properties": {
.
.
.
"Collection": {
"type": "nested",
"properties": {
.
.
.
"FileType": {
"type": "text"
}
}
}
}
}
}
}
}

关于arrays - 过滤对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45832520/

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