我的数据存储在以下格式的弹性搜索中
{
"_index": "wallet",
"_type": "wallet",
"_id": "5dfcbe0a6ca963f84470d852",
"_score": 0.69321066,
"_source": {
"email": "[email protected]",
"wallet": "[email protected]",
"countryCode": "+91",
"phone": "7916318809",
"name": "test20011"
}
},
{
"_index": "wallet",
"_type": "wallet",
"_id": "5dfcbe0a6ca9634d1c70d856",
"_score": 0.69321066,
"_source": {
"email": "[email protected]",
"wallet": "[email protected]",
"countryCode": "+91",
"phone": "3483330496",
"name": "test50011"
}
},
{
"_index": "wallet",
"_type": "wallet",
"_id": "5dfcbe0a6ca96304b370d857",
"_score": 0.69321066,
"_source": {
"email": "[email protected]",
"wallet": "[email protected]",
"countryCode": "+91",
"phone": "2744697207",
"name": "test110021"
}
}
如果我们使用以下查询,则不应找到记录
{
"query": {
"bool": {
"should": [
{
"match": {
"wallet": {
"query": "operatorqa2.akeodev.com",
"operator": "and"
}
}
},
{
"match": {
"email": {
"query": "operatorqa2.akeodev.com",
"operator": "and"
}
}
}
]
}
}
}
记录应该找到我是否在 Query 下方传递
{
"query": {
"bool": {
"should": [
{
"match": {
"wallet": {
"query": "[email protected]",
"operator": "and"
}
}
},
{
"match": {
"email": {
"query": "[email protected]",
"operator": "and"
}
}
}
]
}
}
}
我已经在电子邮件和钱包字段上创建了索引。每当用户通过电子邮件或钱包搜索数据时,我不确定用户发送的任何字符串是电子邮件或钱包,所以我使用bool
.
该记录应查找用户是否发送了完整的电子邮件地址或完整的钱包地址。请帮我找到解决办法
正如其他社区成员所提到的,在提出此类问题时,您应该指定您正在使用的 Elasticsearch 版本并提供映射。
从具有默认映射的 Elasticsearch 版本 5 开始,您只需将查询更改为针对字段的确切版本而不是分析版本进行查询。默认情况下,Elasticsearch 将字符串映射到类型text
(已分析,用于全文搜索)和keyword
(未分析,用于精确匹配搜索)的多字段。在您的查询中,您将针对<fieldname>.keyword
-fields进行查询:
{
"query": {
"bool": {
"should": [
{
"match": {
"wallet.keyword": "[email protected]"
}
},
{
"match": {
"email.keyword": "[email protected]"
}
}
]
}
}
}
如果您使用的是版本 5 之前的 Elasticsearch 版本,请将 index-property 从 更改analyzed
为not_analyzed
并重新索引您的数据。
映射片段:
{
"email": {
"type" "string",
"index": "not_analyzed"
}
}
您的查询仍然不需要使用and
-operator。它看起来与我上面发布的查询相同,除了您必须查询email
和 -wallet
字段,而不是email.keyword
和wallet.keyword
。
我可以向您推荐 Elastic 中与该主题相关的以下博客文章:字符串已死,字符串万岁!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句