【发布时间】:2019-03-16 08:13:36
【问题描述】:
我们有一个弹性搜索 5.5 设置。我们使用 nest 通过 C# 执行查询。
执行以下查询时:
{ "query": { "bool": { "must": [ { "query_string": { "query": "00917751" } } ] } } }
我们得到了想要的结果:一个以数字为标识符的结果。
使用以下查询时:
{ "query": { "bool": { "must": [ { "query_string": { "query": "00917751", "fields": [ "searchReference", "searchIdentifier", "searchObjectNo", "searchBrand", "searchExtSerNo" ] } } ] } } }
我们没有得到任何结果。
我们正在搜索的值在字段 searchIndentifier 中,值为“1-00917751”。
我们有一个名为“final”的自定义分析器
.Custom("final", cu => cu .Tokenizer("keyword").Filters(new List() { "lowercase" }))
字段 searchIndentifier 上没有设置自定义分析器。我们尝试在其中添加空格标记器,但没有任何区别。
当我们尝试使用查询“S328”搜索值“S328-25”时,另一个名为“searchObjectNo”的字段确实有效。这些字段完全相同。
这里有什么想法吗?
另一个问题。在第一个查询中,当我们搜索 1-00917751(不带引号)时,我们会得到很多结果。但我们认为这是因为关键字标记器?
谢谢
Schoof
索引设置和映射:
{
"inventoryitems": {
"aliases": {},
"mappings": {
"inventoryobject": {
"properties": {
"articleGroups": {
"type": "nested",
"properties": {
"id": {
"type": "long"
}
}
},
"articleId": {
"type": "long"
},
"articleNumber": {
"type": "text",
"boost": 1.5,
"analyzer": "final"
},
"brand": {
"type": "text",
"analyzer": "final"
},
"catalogues": {
"type": "nested",
"properties": {
"articleGroupId": {
"type": "long"
},
"articleGroupName": {
"type": "text",
"analyzer": "final",
"fielddata": true
},
"id": {
"type": "long"
},
"name": {
"type": "text",
"analyzer": "final",
"fielddata": true
}
}
},
"details": {
"type": "nested",
"properties": {
"actualState": {
"type": "double"
},
"allocation": {
"type": "text",
"analyzer": "final",
"fielddata": true
},
"available": {
"type": "double"
},
"batch": {
"type": "text",
"analyzer": "final"
},
"calibrationDate": {
"type": "date"
},
"expected": {
"type": "double"
},
"externalSerialNumber": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"inReturn": {
"type": "double"
},
"inventory": {
"type": "double"
},
"isInMobileCarrier": {
"type": "boolean"
},
"locationDetail": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"locationId": {
"type": "long"
},
"locationName": {
"type": "text",
"analyzer": "final",
"fielddata": true
},
"locationType": {
"type": "text",
"analyzer": "final",
"fielddata": true
},
"lotId": {
"type": "long"
},
"mobileCarrierCode": {
"type": "text",
"analyzer": "final",
"fielddata": true
},
"mobileCarrierId": {
"type": "long"
},
"ownerCode": {
"type": "text",
"analyzer": "final"
},
"requested": {
"type": "double"
},
"reserved": {
"type": "double"
},
"storeLocationId": {
"type": "long"
},
"thicknessCode": {
"type": "text",
"analyzer": "final"
},
"weldedMark": {
"type": "text",
"analyzer": "final"
}
}
},
"docNo": {
"type": "long"
},
"hasStock": {
"type": "boolean"
},
"id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"identifier": {
"type": "text",
"boost": 1.5,
"analyzer": "final"
},
"inventoryItemType": {
"properties": {
"name": {
"type": "text",
"analyzer": "final",
"fielddata": true
}
}
},
"mobileCarrierId": {
"type": "long"
},
"name": {
"type": "text",
"boost": 1.5,
"analyzer": "final"
},
"objectNumber": {
"type": "text",
"boost": 1.5,
"analyzer": "final"
},
"quantity": {
"type": "double"
},
"reference": {
"type": "text",
"boost": 1.5,
"analyzer": "final"
},
"searchBrand": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"searchExtSerNo": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"searchIndentifier": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"searchName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"searchObjectNo": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"searchReference": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"sortNumber": {
"type": "long"
},
"stockUnit": {
"type": "text",
"boost": 1.5,
"analyzer": "final"
}
}
}
},
"settings": {
"index": {
"number_of_shards": "3",
"provided_name": "inventoryitems",
"creation_date": "1539253308319",
"analysis": {
"analyzer": {
"final": {
"filter": [
"lowercase"
],
"type": "custom",
"tokenizer": "keyword"
}
}
},
"number_of_replicas": "1",
"uuid": "Kb5KuYEiR5GQqgBPVYjJfA",
"version": {
"created": "5050299"
}
}
}
}
}
【问题讨论】:
-
这将有助于查看您的索引设置和映射。请用您从
curl -XGET localhost:9200/yourindex得到的信息更新您的问题 -
@Val:我们在 windows 环境中托管弹性搜索,我认为 curl 在 windows 上不存在?
-
Powershell ;-) 否则来自 Kibana
GET you-index -
@Val 已添加,谢谢! :)
-
@Schoof 用于 curl,您可以使用适用于 Linux 的 Windows 子系统 (WSL)。如果您想在 PowerShell 中获得类似体验,请查看 gist.github.com/russcam/7fbdbaa37e3dcb3fd3ee0aa54af3708c
标签: elasticsearch nest