我有这样的 Realm :names: ["Red:123", "Blue:45", "Green:56"]
它的映射是
"names": {
"type": "keyword"
},
我怎么能这样搜索{
"query": {
"match": {
"names": "red"
}
}
}
获取red
数组元素中names
的所有文档?现在它仅适用于
{
"query": {
"match": {
"names": "red:123"
}
}
}
最佳答案
您可以添加multi fields或只将类型更改为text
即可实现所需的结果
使用multi fields
的索引映射
{
"mappings": {
"properties": {
"names": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
}
}
}
}
添加带有索引数据,映射,搜索查询和搜索结果的工作示例索引映射:
{
"mappings":{
"properties":{
"names":{
"type":"text"
}
}
}
}
索引数据:{
"names": [
"Red:123",
"Blue:45",
"Green:56"
]
}
搜索查询:{
"query": {
"match": {
"names": "red"
}
}
}
搜索结果:"hits": [
{
"_index": "64665127",
"_type": "_doc",
"_id": "1",
"_score": 0.2876821,
"_source": {
"names": [
"Red:123",
"Blue:45",
"Green:56"
]
}
}
]
关于elasticsearch - 通过在Elasticsearch中部分匹配来搜索字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64665127/