【发布时间】:2014-11-13 07:40:17
【问题描述】:
我正在开发一个建筑存储库查询。
这是我正在尝试编写的查询。
(精确匹配
zipCode) AND ((不区分大小写精确 匹配address1)或(不区分大小写的精确匹配siteName))
在我的存储库中,我有一个如下所示的文档:
address1: 默特尔街 4 号siteName: 默特尔街zipCode: 90210
而且我不断得到匹配:
address1: 45 默特尔街siteName: 默特尔zipCode: 90210
以下是一些无效的尝试:
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"term": {
"address1": {
"value": "45 myrtle street"
}
}
},
{
"term": {
"siteName": {
"value": "myrtle"
}
}
}
]
}
},
{
"term": {
"zipCode": {
"value": "90210"
}
}
}
]
}
}
}
{
"query": {
"filtered": {
"query": {
"term": {
"zipCode": {
"value": "90210"
}
}
},
"filter": {
"or": {
"filters": [
{
"term": {
"address1": "45 myrtle street"
}
},
{
"term": {
"siteName": "myrtle"
}
}
]
}
}
}
}
}
{
"filter": {
"bool": {
"must": [
{
"or": {
"filters": [
{
"term": {
"address1": "45 myrtle street"
}
},
{
"term": {
"siteName": "myrtle"
}
}
]
}
},
{
"term": {
"zipCode": "90210"
}
}
]
}
}
}
{
"query": {
"bool": {
"must": [
{
"span_or": {
"clauses": [
{
"span_term": {
"siteName": {
"value": "myrtle"
}
}
}
]
}
},
{
"term": {
"zipCode": {
"value": "90210"
}
}
}
]
}
}
}
{
"query": {
"filtered": {
"query": {
"term": {
"zipCode": {
"value": "90210"
}
}
},
"filter": {
"or": {
"filters": [
{
"term": {
"address1": "45 myrtle street"
}
},
{
"term": {
"siteName": "myrtle"
}
}
]
}
}
}
}
}
有谁知道我做错了什么?
我是用 NEST 编写的,所以我更喜欢 NEST 语法,但 ElasticSearch 语法当然也足够了。
编辑:根据@Greg Marzouka 的评论,这里是映射:
{
[indexname]: {
"mappings": {
"[indexname]elasticsearchresponse": {
"properties": {
"address": {
"type": "string"
},
"address1": {
"type": "string"
},
"address2": {
"type": "string"
},
"address3": {
"type": "string"
},
"city": {
"type": "string"
},
"country": {
"type": "string"
},
"id": {
"type": "string"
},
"originalSourceId": {
"type": "string"
},
"placeId": {
"type": "string"
},
"siteName": {
"type": "string"
},
"siteType": {
"type": "string"
},
"state": {
"type": "string"
},
"systemId": {
"type": "long"
},
"zipCode": {
"type": "string"
}
}
}
}
}
}
【问题讨论】:
-
也许你应该检查一下 elasticsearch 配置,它是否包含小写过滤器索引?
-
@huwence:我的问题是我的查询符合它不应该匹配的条件。
-
第一个查询看起来不错。我怀疑问题在于如何分析您的字段,尤其是
siteName。介意GET /your-index-name/_mapping?pretty并分享回复吗? -
@GregMarzouka:谢谢。请查看我的编辑。
标签: elasticsearch nest