带有空间的Elasticsearch正则表达式不起作用
假设我有一本书的书名用 索引如下:
curl -XPUT "http://localhost:9200/_river/books/_meta" -d'{
"type": "jdbc",
"jdbc": {
"driver": "org.postgresql.Driver",
"url": "jdbc:postgresql://localhost:5432/...",
"user": "...",
"password": "...",
"index": "books",
"type": "books",
"sql": "SELECT * FROM books"}
}’
例如,我有一本书叫"Afoo barb"
。
以下代码(搜索'.*foo.*'
)可以很好地返回书中:
client.search({ index: 'books',
'from': 0,
'size': 10,
'body' : {
'query': {
'filtered': {
'filter': {
'bool': {
'must': {
'regexp': { title: '.*foo.*' }
}
}
}
}
}
}
});
但是以下代码(搜索'.*foo bar.*'
)没有:
client.search({ index: 'books',
'from': 0,
'size': 10,
'body' : {
'query': {
'filtered': {
'filter': {
'bool': {
'must': {
'regexp': { title: '.*foo bar.*' }
}
}
}
}
}
}
});
我试图用'\s'
或替换空格,'.*'
但是它也不起作用。
我认为标题以(['Afoo', 'barb']
)分隔,因此找不到'.*foo bar.*'
。
如何要求Elasticsearch在完整标题中搜索regexp?
回答:
Elasticsearch会将正则表达式应用于令牌生成器针对该字段生成的术语,而不应用于该字段的原始文本。
您可以使用其他令牌生成器为字段建立索引,也可以定义正则表达式,使其返回具有较高分数的必需文档。
关键字标记器的示例:
'regexp': { title: '*(foo bar)*' }
以上是 带有空间的Elasticsearch正则表达式不起作用 的全部内容, 来源链接: utcz.com/qa/406900.html