【发布时间】:2016-01-11 12:42:10
【问题描述】:
我需要修复由 Elasticsearch 1.7.x 支持的搜索实现。我们遇到的主要问题是返回的搜索结果的相关性。
出于各种原因,我正在从命令行尝试一些非常基本的查询(我的意思是 this basic: https://www.elastic.co/guide/en/elasticsearch/guide/1.x/query-dsl-intro.html)。
我有一个包含两个文档的索引,如下:
{
"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 字段。我从命令行使用以下查询:
curl -XGET http://localhost:9200/merchantv2/_search -d '
{
"query": {
"match": {
"businessName": "test"
}
}
}'
我希望它匹配 businessName 设置为“测试商家”的文档,但实际上我没有返回任何匹配项:
{"took":45,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}
我通过以下搜索词得到了类似的结果:test*、*test*、Test、Test Merchant、test merchant。
鉴于businessName 是顶级属性,我对此感到有些困惑。请问大家有什么想法吗?
编辑 - 忘记包含映射
这是businessName 字段的映射:
"businessName":{
"type":"string"
},
【问题讨论】:
-
你不会删除这个吧? ;-)
-
哈哈 - 不。在这种情况下,我认为这不仅仅是一个错字。
-
请注意,
match查询不支持通配符(即test*和*test*),但其他四个应该可以工作。 -
您可以尝试使用
-XPOST而不是-XGET,因为您正在发送有效负载?
标签: elasticsearch