我是ES的新手,想要设置查询以搜索多个字词。
我的SQL看起来像:
"SELECT field4 FROM tablename WHERE (field1 = 'A' OR field1 = 'AA') AND (field2 = 'B' OR fields2 = 'BB') AND (field3 = 'C' OR field3 = 'CC')"
在ES中我尝试
{
"query": {
"bool": {
"must": [
{
"term": {
"field1": {"A","AA"}
}
},
{
"term": {
"field2": {"B","BB"}
}
},
{
"term": {
"field3": {"C","CC"}
}
}
}
}
}
答案 0 :(得分:2)
您最想要的是terms
查询。您可以在此处查看相关文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html
该网站的一个例子是:
{
"terms" : { "user" : ["kimchy", "elasticsearch"]}
}
此外,您的查询现在不是有效的json,您需要更正它。