【发布时间】:2019-05-07 10:21:51
【问题描述】:
您好,我在弹性搜索中有数百万条记录,其中我的一个字段(textlowercase)属于“文本”类型。
现在我想在这个“文本”类型字段中搜索多个单词,我该怎么做。
问题在于,由于它是一个文本字段,因此会对其进行分析并拆分为标记。 例如:在 SQL 中我想要这样的东西
select textlowercase from table where textlowercase like '%abc%' or '%bbc%' or '%my text%'
我尝试过“未分析”并将类型更改为“关键字”并没有帮助。
我正在使用弹性搜索 7
这是我的映射:
{
"settings": {
"analysis": {
"normalizer": {
"lowercase_normalizer": {
"type": "custom",
"char_filter": [
],
"filter": [
"lowercase"
]
}
},
"analyzer": {
"my_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase"
]
}
}
}
},
"fbdata": {
"mappings": {
"properties": {
"createdatutc": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"createdbyname": {
"type": "keyword"
},
"groupname": {
"type": "keyword"
},
"id": {
"type": "keyword"
},
"insertedatutc": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"postid": {
"type": "keyword"
},
"posttype": {
"type": "keyword"
},
"posturl": {
"type": "keyword"
},
"textlowercase": {
"type": "text",
"analyzer": "my_analyzer",
"fielddata": true
}
}
}
}
}
这是我的查询
{
"index": "fbdata",
"type": "_doc",
"body": {
"from": 0,
"size": 500000,
"query": {
"bool": {
"should": [ {
"match": {
"textlowercase": "*cowmilk*"
}
}, {
"match": {
"textlowercase": "*Gaay ka doodh*"
}
}, {
"match": {
"textlowercase": "*cow ka*"
}
}, {
"match": {
"textlowercase": "*bakri ka*"
}
}, {
"match": {
"textlowercase": "*goatmilk*"
}
}],
"must": [{
"range": {
"createdatutc": {
"gte": "2019-01-01",
"lt": "2019-03-31",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd"
}
}
}]
}
}
}
}
【问题讨论】:
-
@VikashKumarVerma 请将此作为答案发布,以便我接受
标签: elasticsearch