我有这个sql
Select * from a where a.col1 like %search_str% OR a.col2 like %search_str% OR a.col3 like %search_str%;
弹性搜索查询的内容是什么?
使用它:
var query = {
"query" => {
"multi_match" => {
"query" => "#{search_str}",
"fields" =>["col1","col2","col3"]
}
}
}
没有得到非常准确的结果。
答案 0 :(得分:0)
尝试以下代码
> compareCollection(db.col1, db.col4)
false
答案 1 :(得分:0)
如果您将研究限制在相同或类似的操作,则不需要分析文本。
将映射更改为关键字以避免分析,然后使用通配符或正则表达式搜索单个整个文本块。
有关详细信息,请参阅here。
PUT _template/test
{
"template": "test-*",
"settings": {
"analysis": {
"normalizer": {
"my_normalizer": {
"type": "custom",
"char_filter": [],
"filter": ["lowercase", "asciifolding"]
}
}
}
},
"mappings": {
"_default_": {
"_all": {
"enabled": false
},
"dynamic_templates": [
{
"strings_as_keywords": {
"match_mapping_type": "string",
"mapping": {
"type": "keyword",
"normalizer": "my_normalizer"
}
}
}
]
}
}
}
这是一个为名称 test - 开头的所有新索引创建模板的示例:
并且您可能希望将查询转换为过滤器以准确匹配您的项目并且不使用分数系统
GET /test-1/movies/_search
{
"query": {
"bool": {
"filter": {
"bool": {
"should": [
{
"wildcard": {
"title": "*tar war*"
}
},
{
"wildcard": {
"title": "*ord of the ring*"
}
}
]
}
}
}
}
}