用户通过 elasticsearch 创建复杂的查询和搜索 [英] user create complex query and search over elasticsearch

查看:16
本文介绍了用户通过 elasticsearch 创建复杂的查询和搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户是否可以创建复杂的查询并阐明从 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 支持更复杂的语法,但不建议在搜索框中使用它,因为任何无效语法都会返回错误.

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 创建复杂的查询和搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆