我的数据库充满了这样的文件:
{
_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,那么您想要排除的是仅包含/
的所有文档。到底。看到如果您的字符串始终带有1个字符,那么您总是将数据存储为/path
,那么它应该始终是/
,那么为什么不使用正则表达式呢?
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-regexp-filter.html
我认为类似这样的方法应该可以解决问题:
{
"query": {
"filtered": {
"filter": {
"and": [
{
"bool": {
"should": {
"terms": {
"keywords": [
"stackoverflow",
"rocks",
"!"
]
}
}
}
},
{
"filter": {
"regexp": {
"path": ".{1,}"
}
}
}
]
}
}
},
"from": 0,
"size": 9
}
关于string - Elasticsearch一开始不能使用斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27785275/