Search 如何在弹性搜索中使用split_on_空格?
我想在搜索查询中对空格使用split\u,但无法解决这个问题。查询将有一个类似“hello world”的字符串。我不想分割查询词首先,确保不分析要搜索的字段的映射。这样ES就不会分析字段中的单词并将其存储为单个文本 因此,您的映射将类似于:Search 如何在弹性搜索中使用split_on_空格?,search,
elasticsearch,Search,
elasticsearch,我想在搜索查询中对空格使用split\u,但无法解决这个问题。查询将有一个类似“hello world”的字符串。我不想分割查询词首先,确保不分析要搜索的字段的映射。这样ES就不会分析字段中的单词并将其存储为单个文本 因此,您的映射将类似于: curl -XPUT localhost:9200/index_name -d '{ "mappings": { "type_name": { "properties": {
curl -XPUT localhost:9200/index_name -d '{
"mappings": {
"type_name": {
"properties": {
"field_to_search": {
"type": "string",
"index": "not_analyzed"
},
...(other fields)
}
}
}
}
然后可以对字段执行术语查询
curl -XPOST localhost:9200/index_name/type_name/_search -d '{
"query": {
"term": {
"field_to_search": "hello world"
}
}
}
您可以查看elasticsearch的术语查询和匹配查询之间的区别,以了解为什么需要术语查询