【发布时间】:2020-04-21 01:56:28
【问题描述】:
我是弹性搜索的新手,我厌倦了在索引文档中查找数据。就像我有 4 个文档,并且有 2 个字段 fullName, userName -
{
"_index": "users",
"_type": "users",
"_id": "NwV2GG8BmEFrScbl3IE8",
"_score": 1,
"_source": {
"fullName": "Max Payne",
"id": 1,
"userName": "MaxP"
}
},
{
"_index": "users",
"_type": "users",
"_id": "MgV2GG8BmEFrScbl3IE8",
"_score": 1,
"_source": {
"fullName": "Thomas John",
"id": 6,
"userName": "ThomesJ"
}
},
{
"_index": "users",
"_type": "users",
"_id": "MgD2TG1BmEFrrfbs3RT9",
"_score": 1,
"_source": {
"fullName": "John well",
"id": 7,
"userName": "ThomesW"
}
},
{
"_index": "users",
"_type": "users",
"_id": "QwR58DTBmEFrScbl8op4",
"_score": 1,
"_source": {
"fullName": "Max smith",
"id": 1,
"userName": "MaxS"
}
}
如果搜索 情况1 'Ma' 那么我需要 3 个文件
案例 2 'Max' 那么我需要 2 个文档
案例 3 'Max s' 然后我需要 1 个文件 (Max smith) 'Max p' 然后我需要 1 个文件(Max Payne)
案例 4 'John' 那么我需要 2 个文件
我试试这个,如果完整的字符串匹配,则找到数据,否则找不到数据。
"bool" : {
"should": {
"query_string": {
"query": '*'+keyword+'*', // "query": keyword+'*',
"fields": [ "fullName", "userName" ]
},
},
}
另外,我尝试了这个但不起作用
"term": {
"fullName": {
"value": keyword
}
}
我在 NodeJs 客户端中使用 Elasticsearch 6.3
【问题讨论】:
标签: elasticsearch nodes