我想字符串完全匹配":Feed:"的message 领域,每天回去把所有这些记录.我的json似乎也与简单的单词相匹配" feed ".我不确定我哪里出错了.我是否需要添加"constant_score"此查询JSON?我目前的JSON如下所示:
{
"query": {
"bool": {
"must": {
"query_string": {
"fields": ["message"],
"query": "\\:Feed\\:"
}
},
"must": {
"range": {
"timestamp": {
"gte": "now-1d",
"lte": "now"
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
Har*_*and 12
使用匹配短语
GET /_search
{
"query": {
"match_phrase": {
"message": "7000-8900"
}
}
}
Run Code Online (Sandbox Code Playgroud)
在java中使用QueryBuilder的matchPhraseQuery
QueryBuilders.matchPhraseQuery(fieldName, searchText);
Run Code Online (Sandbox Code Playgroud)
Arv*_*mar 10
无法做到这一点,query_string但设法通过创建自定义规范化器然后使用“匹配”或“术语”查询来做到这一点。
以下步骤对我有用。
创建自定义规范器(可用 > V5.2)
"settings": {
"analysis": {
"normalizer": {
"my_normalizer": {
"type": "custom",
"filter": ["lowercase"]
}
}
}
Run Code Online (Sandbox Code Playgroud)
}
创建一个类型为“keyword”的映射
{
"mappings": {
"default": {
"properties": {
"title": {
"type": "text",
"fields": {
"normalize": {
"type": "keyword",
"normalizer": "my_normalizer"
},
"keyword" : {
"type": "keyword"
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)使用匹配或术语查询
{
"query": {
"bool": {
"must": [
{
"match": {
"title.normalize": "string to match"
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)term查询..GET /_search
{
"query": {
"term": {
"message.keyword": "7000-8900"
}
}
}
Run Code Online (Sandbox Code Playgroud)
term查询代替match_phrase,match_phrase这个find/match与ES-document存储的句子,它不会完全匹配。和那句话很配啊!| 归档时间: |
|
| 查看次数: |
20962 次 |
| 最近记录: |