0
我是elatic搜索的新手,不幸的是elasticearch.com文档不够好。我知道如何使用术语:如何使用标准组合来构建弹性查询?
{
"term" : { "user" : "kimchy" }
}
您能否帮助我通过这些标准来构建我的查询? (用户= “伊赫桑” 或用户= “afsaneh”)和((10和20之间的年龄)或40和50之间的(年龄))
我是elatic搜索的新手,不幸的是elasticearch.com文档不够好。我知道如何使用术语:如何使用标准组合来构建弹性查询?
{
"term" : { "user" : "kimchy" }
}
您能否帮助我通过这些标准来构建我的查询? (用户= “伊赫桑” 或用户= “afsaneh”)和((10和20之间的年龄)或40和50之间的(年龄))
你应该看看:
bool
查询(documentation):它会帮助你在不同的指标分析与AND/OR/NO使用条款结合must
/should
/must_not
range
过滤器(documentation):它的目标是要排除不值相匹配的文件你设定的间隔。下面的查询应该做的伎俩:
{
"query": {
"filtered": {
"query": {
"bool": {
"should": [
{
"term": {
"user": "ehsan"
}
},
{
"term": {
"user": "afsaneh"
}
}
]
}
},
"filter": {
"or": {
"filters": [
{
"range": {
"age": {
"from": 10,
"to": 20
}
}
},
{
"range": {
"age": {
"from": 40,
"to": 50
}
}
}
]
}
}
}
}
}
但是,恕我直言,在Elasticsearch文档是相当不错的。 为了了解如何构建其他查询,您应该花时间阅读更多内容:像这样(特别是关于difference between query and filters)。
编辑:
"terms": {
"user": [
"ehsan",
"afsaneh"
]
}
:两个
term
查询可以通过一个单一的
terms
像这样被替换