【发布时间】:2017-01-21 11:31:03
【问题描述】:
我使用的是 elastic 2.2 和 Sense。
我有以下问题要澄清我的一种想法。
Elasticsearch 是一个全文搜索引擎,而不是一个 SQL 数据库,但是在 ES 查询中仍然可以考虑代数(AND、OR、WHERE 等)。
我不在乎这方面的分数。
假设我有以下平面文档类型客户,其中所有字段都未分析,映射中的属性是:
"properties": {
"address": {
"type": "string",
"index": "not_analyzed"
},
"age": {
"type": "long"
},
"customerid": {
"type": "string",
"index": "not_analyzed"
},
"firstname": {
"type": "string",
"index": "not_analyzed"
},
"lastname": {
"type": "string",
"index": "not_analyzed"
},
"updated": {
"type": "date",
"format": "date_hour_minute_second_millis"
}
}
现在我索引:
PUT customers_ds/customers/1
{
"customerid": "1",
"firstname": "Marie",
"address": "Brazil",
"updated": "2017-01-13T02:36:37.292",
"lastname": "Doe",
"age": 20
}
PUT customers_ds/customers/2
{
"customerid": "1",
"firstname": "John",
"address": "North America",
"updated": "2017-01-13T02:36:37.292",
"lastname": "Doe",
"age": 25
}
我应该写什么查询:
我希望所有名字为 Marie 或居住在“北美”的客户
select * from customers where firstname = "Marie" or address = "North America"
这样的ES查询怎么写?
最后,怎么写:
select * from customers where firstname = "Marie" and lastname = "Doe" or address = "North America"
在最后一个查询中,我想从 ES 中返回:
玛丽和约翰,因为 OR。或 address = "North America",而 Mary 将在 AND 中匹配。让我知道这是否清楚。
???
【问题讨论】:
-
"分析所有字段的地方" => 映射中的所有字符串字段都是
not_analyzed。你能澄清一下吗? -
HI @Val - 我的意思是所有字段都没有被分析。我现在正在编辑它
标签: java sql elasticsearch lucene full-text-search