问题描述
用户是否可以创建复杂的查询并阐明从ui进行搜索以及在Elasticsearch中进行搜索的条件?我知道弹性搜索中的布尔查询,但是我需要实现这样的查询,即每次用户都可以为我发送不同的条件,例如<,>,!=和...
Is it possible user create complex query and clarify conditions for search from ui and search in elasticsearch? I know about boolean query in elastic search , but i need to implement my query that elach time user could send different condition for me like , < , > , != and ...
推荐答案
实际上,有两种方法可以从用户输入中接受运算符:
In fact, there are two ways to accept operators from the user input :
simple_query_string
simple_query_string查询支持以下运算符:
The simple_query_string query supports the following operators:
+ signifies AND operation
| signifies OR operation
- negates a single token
" wraps a number of tokens to signify a phrase for searching
* at the end of a term signifies a prefix query
( and ) signify precedence
~N after a word signifies edit distance (fuzziness)
~N after a phrase signifies slop amount
示例
GET /_search
{
"query": {
"simple_query_string" : {
"query": "\"fried eggs\" +(eggplant | potato) -frittata",
"fields": ["title^5", "body"],
"default_operator": "and"
}
}
}
query_string
query_string支持更复杂的语法,但是不建议在搜索框中使用它,因为对于任何无效的语法都会返回错误.
The query_string supports more complex syntax but it is not recommended to use it on search boxes because returns an error for any invalid syntax.
示例
GET /_search
{
"query": {
"query_string": {
"query": "(new york city) OR (big apple)",
"default_field": "content"
}
}
}
这篇关于用户创建复杂的查询并通过elasticsearch搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!