我在使用Elasticsearch 1.7.x打球方面遇到了一些麻烦 - 我一直试图通过已经使用它的搜索来实现错误修复和一些额外的评分功能,但是通常包含不相关的结果。
因此我决定回到绝对基础,使用以下查询:
curl -XGET http://localhost:9200/merchantv2/_search '
{
"query": {
"match": {
"businessName": "test"
}
}
}'
目前我的索引中只有两个文件。一个businessName
设置为"测试商家",我希望上述查询匹配,另一个将businessName设置为"",我和# 39; d期望不匹配。
但是,运行该精确查询的结果如下:
{
"took":1,
"timed_out":false,
"_shards":{
"total":5,
"successful":5,
"failed":0
},
"hits":{
"total":2,
"max_score":1.0,
"hits":[
{
"_index":"merchantv2",
"_type":"searchablemerchant",
"_id":"00000000-0000-0000-0000-000000000000",
"_score":1.0,
"_source":{
"merchantGuid":"00000000-0000-0000-0000-000000000000",
"v1MerchantId":0,
"locatorId":"0",
"address":{
"addressGuid":"00000000-0000-0000-0000-000000000000",
"postCodeDetails":{
"postCodeKey":0,
"postalDistrict":{
"postalDistrictKey":0,
"postalDistrict":""
},
"postalLocation":"0",
"latitude":0.0,
"longitude":0.0,
"townName":"None",
"countyKey":0,
"countryKey":0,
"postCode":{
"postCodeKey":0,
"postCode":" 0"
}
},
"county":{
"countyKey":0,
"countyName":"",
"countryKey":0,
"recStatus":3,
"countryKeyValue":0
},
"countryKey":0,
"addressTypeKey":0,
"updateDate":"0001-01-01T00:00:00+00:00",
"createdDate":"2016-01-07T19:46:28.4463+00:00"
},
"searchableAddress":" 0",
"searchablePhone":"",
"searchableFax":"",
"businessName":"",
"contacts":[
],
"opportunities":[
{
"opportunityGuid":"00000000-0000-0000-0000-000000000000",
"merchantGuid":"00000000-0000-0000-0000-000000000000",
"location":{
"locationGuid":"00000000-0000-0000-0000-000000000000",
"tradingAddress":{
"verified":false,
"addressGuid":"00000000-0000-0000-0000-000000000000",
"postCodeDetails":{
"postCodeKey":0,
"postalDistrict":{
"postalDistrictKey":0,
"postalDistrict":""
},
"postalLocation":"0",
"latitude":0.0,
"longitude":0.0,
"townName":"None",
"countyKey":0,
"countryKey":0,
"postCode":{
"postCodeKey":0,
"postCode":" 0"
}
},
"county":{
"countyKey":0,
"countyName":"",
"countryKey":0,
"recStatus":3,
"countryKeyValue":0
},
"countryKey":0,
"addressTypeKey":0,
"updateDate":"0001-01-01T00:00:00+00:00",
"createdDate":"2016-01-07T19:46:28.4463+00:00"
}
},
"opportunityLocatorId":"000000"
}
]
}
},
{
"_index":"merchantv2",
"_type":"searchablemerchant",
"_id":"5f55fe61-ca65-e411-93f3-0cc47a07ef4a",
"_score":1.0,
"_source":{
"merchantGuid":"5f55fe61-ca65-e411-93f3-0cc47a07ef4a",
"locatorId":"PM227Z02",
"address":{
"addressGuid":"5c55fe61-ca65-e411-93f3-0cc47a07ef4a",
"houseNumber":"242",
"streetName":"Acklam Road",
"houseName":"",
"flatAptSuite":"",
"townName":"London",
"postCodeDetails":{
"postCodeKey":1,
"postalDistrict":{
"postalDistrictKey":2782,
"postalDistrict":"W10"
},
"postalLocation":"5JJ",
"latitude":51.52094651,
"longitude":-0.20149990,
"townName":"London",
"countyKey":0,
"countryKey":224,
"postCode":{
"postCodeKey":1,
"postCode":"W10 5JJ"
}
},
"county":{
"countyKey":626,
"countyName":"Kensington And Chelsea",
"countryKey":224,
"recStatus":1,
"countryKeyValue":224
},
"countryKey":224,
"addressTypeKey":0,
"updateDate":"0001-01-01T00:00:00+00:00",
"createdDate":"2016-01-07T19:46:28.4653+00:00"
},
"searchableAddress":"242 Acklam Road, London, Kensington And Chelsea, W10 5JJ",
"searchablePhone":"+44 2031954484",
"searchableFax":"",
"businessName":"Test Merchant",
"contacts":[
],
"opportunities":[
]
}
}
]
}
}
请注意,有两个匹配,其中一个是空businessName
的文档。
WT ...?
有人可以向我解释为什么会这样吗?
(我已使用https://www.elastic.co/guide/en/elasticsearch/guide/1.x/query-dsl-intro.html的查询条款结构下的第一个match
示例查询作为模板。)
编辑:完全是我的坏事(我很高兴地说)
与Elasticsearch无关。我正在整个地方复制并粘贴curl
命令,然后对这一命令进行过度编辑。缺少-d标志意味着查询文档未提交给Elasticsearch,从而有效地将我的命令转换为:
curl -XGET http://localhost:9200/merchantv2/_search
当然,这会返回索引中的所有文档。 #facepalm
答案 0 :(得分:1)
使用curl发送搜索有效负载时,您需要使用-d
命令行开关,否则您只是在没有约束的情况下点击_search
端点:
this is missing
|
V
curl -XGET http://localhost:9200/merchantv2/_search -d '
{
"query": {
"match": {
"businessName": "test"
}
}
}'