我有这样的字段:
names: ["Red:123", "Blue:45", "Green:56"]
它的映射是
"names": {
"type": "keyword"
},
我怎么能这样搜索
{
"query": {
"match": {
"names": "red"
}
}
}
要获取red
数组中names
所在元素的所有文档?
现在仅适用于
{
"query": {
"match": {
"names": "red:123"
}
}
}
答案 0 :(得分:1)
您可以添加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"
]
}
}
]