我的数据库充满了这样的文件:
{
_index: "bla_bla",
.
.
.
_source: {
domain: "somedomain.extension",
path: "/you/know/the/path",
lang: "en",
keywords: ["yeah", "you", "rock", "dude", "help", "me", "good", "samaritan"]
}
}
当我搜索时-无论我要寻找什么-它都像一种魅力,但是,如果我尝试通过使用名为path的字段进行过滤,则-根本不起作用;不会引发任何错误或警告。经过详尽的研究,我想这是因为路径开始处的斜杠可能是对的还是不正确的,但无论如何我都需要这样过滤:
{
"query": {
"filtered": {
"filter": {
"bool": {
"should": {
"terms": {
"keywords": ["stackoverflow", "rocks", "!"]
}
},
"must_not": {
"term": {
"path": "/"
// This works, i.e -> "lang": "en"
}
}
}
}
}
},
"from": 0,
"size": 9
}
TL; DR:拥有一个url数据库,如何仅获取非根[路径长于“ /”的非根用户]?
免责声明:我不是ES方面的专家,但如果正确理解ES,您想要排除的是仅包含所有文档/
。到底。看到您总是将数据存储为/path
好像您始终拥有一个带有1个字符的字符串一样/
,那么为什么不使用正则表达式呢?
我认为类似这样的方法应该可以解决问题:
{
"query": {
"filtered": {
"filter": {
"and": [
{
"bool": {
"should": {
"terms": {
"keywords": [
"stackoverflow",
"rocks",
"!"
]
}
}
}
},
{
"filter": {
"regexp": {
"path": ".{1,}"
}
}
}
]
}
}
},
"from": 0,
"size": 9
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句