我正在使用弹性搜索来索引我的文档,并希望根据特定属性过滤文档。这是我的代码:
filter.push({
range: {"audience.ethnicity.asian" : { gt: 50 } }
})
它不适用于 gt 运算符(发回不一致的结果),但适用于 lt 运算符
filter.push({
range: {"audience.ethnicity.asian" : { lt: 50 } }
})
这很有效。我已仔细检查属性值是否为整数。我尝试了很多不同的方法,但似乎无法弄清楚我错过了什么。
映射:
"audience": {
"properties": {
"age": {
"properties": {
"13-17": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"18-24": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"25-34": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"35-44": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"45-64": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"eighteen": {
"type": "long"
},
"fortyfive": {
"type": "long"
},
"thirteen": {
"type": "long"
},
"thirtyfive": {
"type": "long"
},
"twentyfive": {
"type": "long"
}
}
},
"ages": {
"properties": {
"13-17": {
"type": "float"
},
"18-24": {
"type": "float"
},
"25-34": {
"type": "float"
},
"35-44": {
"type": "float"
},
"45-64": {
"type": "float"
}
}
},
"ethnicity": {
"properties": {
"African American": {
"type": "float"
},
"Asian": {
"type": "float"
},
"Hispanic": {
"type": "float"
},
"White / Caucasian": {
"type": "float"
},
"african": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"asian": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"hispanic": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"white": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"gender": {
"properties": {
"female": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"male": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"genders": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
},
"gendersPerAge": {
"properties": {
"13-17": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
},
"18-24": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
},
"25-34": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
},
"35-44": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
},
"45-64": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
}
}
}
}
} "audience": {
"properties": {
"age": {
"properties": {
"13-17": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"18-24": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"25-34": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"35-44": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"45-64": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"eighteen": {
"type": "long"
},
"fortyfive": {
"type": "long"
},
"thirteen": {
"type": "long"
},
"thirtyfive": {
"type": "long"
},
"twentyfive": {
"type": "long"
}
}
},
"ages": {
"properties": {
"13-17": {
"type": "float"
},
"18-24": {
"type": "float"
},
"25-34": {
"type": "float"
},
"35-44": {
"type": "float"
},
"45-64": {
"type": "float"
}
}
},
"ethnicity": {
"properties": {
"African American": {
"type": "float"
},
"Asian": {
"type": "float"
},
"Hispanic": {
"type": "float"
},
"White / Caucasian": {
"type": "float"
},
"african": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"asian": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"hispanic": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"white": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"gender": {
"properties": {
"female": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"male": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"genders": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
},
"gendersPerAge": {
"properties": {
"13-17": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
},
"18-24": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
},
"25-34": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
},
"35-44": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
},
"45-64": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
}
}
}
}
}