保留ElasticSearch查询中的条款顺序 [英] Preserving order of terms in ElasticSearch query
问题描述
一个简单的例子是使用标准分析器对这些文档进行索引:
ElasticSearch中是否可能形成一个保留条款顺序的查询。 / p>
- 你知道搜索
- 你知道搜索
- 知道搜索你
我可以查询 +你+搜索
将给我所有的文件,包括第三个。
如果我只想检索具有这个特定顺序的条款的文件怎么办?我可以形成一个对我来说的查询?
考虑到短语可以通过简单的引用文本:你知道 / code>(检索第一和第二个文档)感觉对我来说,应该有一种方式来保持与不相邻的多个条款的顺序。
在上面的简单示例中,我可以使用邻近搜索,但这不包括更复杂的情况。
您可以使用一个 span_near
查询,它有一个 in_order
参数。
{
查询:{
span_near:{
子句:[
{
span_term :{
field:你
}
},
{
span_term:{
field:search
}
}
],
slop:2,
in_order:true
}
}
}
Is it possible in ElasticSearch to form a query that would preserve the ordering of the terms?
A simple example would be having these documents indexed using standard analyzer:
- You know for search
- You know search
- Know search for you
I could query for +you +search
and this would return me all documents, including the third one.
What if I wanted to only retrieve the documents which have the terms in this specific order? Can I form a query that would do that for me?
Considering it is possible for phrases by simply quoting the text: "you know"
(retrieve 1st and 2nd docs) it feels to me like there should be a way of preserving the order for multiple terms that aren't adjacent.
In the above simple example I could use proximity searches, but this doesn't cover more complex cases.
You could use a span_near
query, it has a in_order
parameter.
{
"query": {
"span_near": {
"clauses": [
{
"span_term": {
"field": "you"
}
},
{
"span_term": {
"field": "search"
}
}
],
"slop": 2,
"in_order": true
}
}
}
这篇关于保留ElasticSearch查询中的条款顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!