Elasticsearch DSL多字段多词条查询怎么写?
How to write Elasticsearch DSL multi field and multi term query?
我应该如何将 Elasticsearch (6.6) DSL 查询编写到 return 仅记录此示例池中的 Doc2 和 Doc3:
Doc1 { "Field1" : "Term1", "Field2" : "Term2" }
Doc2 { "Field1" : "Term6", "Field2" : "Term2" }
Doc3 { "Field1" : "Term6", "Field2" : "Term5" }
Doc4 { "Field1" : "Term3", "Field2" : "Term1" }
查询逻辑: (Field1 or Field2) 不等于 (Term1 or Term2 or Term3)
假设 Field1
和 Field2
的数据类型是关键字,您可以使用 should 和 bool query with terms query 的 must_not 子句来获得所需的结果。
查询如下所示:
{
"query": {
"bool": {
"should": [
{
"bool": {
"must_not": [
{
"terms": {
"Field1": [
"Term1",
"Term2",
"Term3"
]
}
}
]
}
},
{
"bool": {
"must_not": [
{
"terms": {
"Field2": [
"Term1",
"Term2",
"Term3"
]
}
}
]
}
}
]
}
}
}
我应该如何将 Elasticsearch (6.6) DSL 查询编写到 return 仅记录此示例池中的 Doc2 和 Doc3:
Doc1 { "Field1" : "Term1", "Field2" : "Term2" }
Doc2 { "Field1" : "Term6", "Field2" : "Term2" }
Doc3 { "Field1" : "Term6", "Field2" : "Term5" }
Doc4 { "Field1" : "Term3", "Field2" : "Term1" }
查询逻辑: (Field1 or Field2) 不等于 (Term1 or Term2 or Term3)
假设 Field1
和 Field2
的数据类型是关键字,您可以使用 should 和 bool query with terms query 的 must_not 子句来获得所需的结果。
查询如下所示:
{
"query": {
"bool": {
"should": [
{
"bool": {
"must_not": [
{
"terms": {
"Field1": [
"Term1",
"Term2",
"Term3"
]
}
}
]
}
},
{
"bool": {
"must_not": [
{
"terms": {
"Field2": [
"Term1",
"Term2",
"Term3"
]
}
}
]
}
}
]
}
}
}