弹性搜索复数邻近查询 [英] Elasticsearch complex proximity query
问题描述
理事会* W / 5(提示或提示)
上述查询可以翻译为:查找任何具有议会* 和或提示)不超过5个字。
所以以下文字将匹配:
- Shellharbour City 理事会提示
- 理事会最佳提示
- 理事会前10名提示
但是不应该匹配:
- ... Shellharbour的城市理事会。没有任何好的提示。
我需要帮助来构建弹性搜索查询。我正在考虑正则表达式查询,但我不太清楚更好的选择。感谢
您可以使用 span_near 查询,span_multi 和 span_or 。我们可以使用下面的查询来执行相同的搜索。
{
query:{
span_near:{
clauses:[
{
span_multi:
{
match:
{
前缀:{text:委员会}
}
}
},
{
span_or:{
子句 [
{
span_term:{
text:{
value:tip
}
}
} ,
{
span_term:{
text:{
value:tips
}
}
}
]
}
}
],
slop:5,
in_order:true
}
}
}
要查找的重要内容是 span_term ,它是您搜索的文本。在这个例子中,我只有一个字段叫做文本。 Slop 表示我们将允许的词语数量,而 in_order 表示单词的顺序很重要。所以提议委员会将不匹配,理事会提示将在哪里。
Given that I have a query like below:
council* W/5 (tip OR tips)
The above query can be translated as: Find anything that has council* and (tip OR tips) no more than 5 words apart.
So following text will match:
- Shellharbour City Council Tip
- council best tip
- councils top 10 tips
But this one should not match:
- ... City Council at Shellharbour. There is not any good tip at all.
I need help to build an elasticsearch query for that. I was thinking about Regex query but I'm not quite sure about better alternatives. Thanks
You can use a combination of the span_near query, span_multi and span_or. We can use the query below to perform the same search.
{
"query": {
"span_near": {
"clauses": [
{
"span_multi":
{
"match":
{
"prefix": { "text": "council"}
}
}
},
{
"span_or": {
"clauses": [
{
"span_term": {
"text": {
"value": "tip"
}
}
},
{
"span_term": {
"text": {
"value": "tips"
}
}
}
]
}
}
],
"slop": 5,
"in_order": true
}
}
}
The important things to look out for are the span_term which is the text your searching for. In this example I only had one field called "text". Slop indicates the number of words we will allow between the terms, and in_order indicates that the order of words is important. So "tip council" will not match, where as "council tip" will.
这篇关于弹性搜索复数邻近查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!