美文网首页
3.9-QueryString&SimpleQueryStrin

3.9-QueryString&SimpleQueryStrin

作者: 落日彼岸 | 来源:发表于2020-03-17 16:20 被阅读0次

    Query String Query

    • 类似URI Query
    POST users/_search
    {
      "query": {
        "query_string": {
          "default_field": "name",
          "query": "Ruan AND Yiming"
        }
      }
    }
    
    POST users/_search
    {
      "query": {
        "query_string": {
          "fields":["name","about"],
          "query": "(Ruan AND Yiming) OR (Java AND Elasticsearch)"
        }
      }
    }
    

    Simple Query String Query

    POST users/_search
    {
      "query": {
        "simple_query_string": {
          "query": "Ruan Yiming",
          "fields": ["name"],
          "default_operator": "AND"
        }
      }
    }
    
    • 类似Query Sting,但是会忽略错误的语法,同时只支持部分查询语法

    • 不支持 AND OR NOT, 会当作字符处理

    • Term 之间默认的关系是OR,可以指定Operator

    • 支持部分逻辑

      • +替代AND

      • |替代OR

      • -替代NOT

    课程 Demo

    • 需导入Movie测试数据,具体参考“2.4-Logstash安装与导入数据”
    PUT /users/_doc/1
    {
      "name":"Ruan Yiming",
      "about":"java, golang, node, swift, elasticsearch"
    }
    
    PUT /users/_doc/2
    {
      "name":"Li Yiming",
      "about":"Hadoop"
    }
    
    
    POST users/_search
    {
      "query": {
        "query_string": {
          "default_field": "name",
          "query": "Ruan AND Yiming"
        }
      }
    }
    
    
    POST users/_search
    {
      "query": {
        "query_string": {
          "fields":["name","about"],
          "query": "(Ruan AND Yiming) OR (Java AND Elasticsearch)"
        }
      }
    }
    
    
    #Simple Query 默认的operator是 Or
    POST users/_search
    {
      "query": {
        "simple_query_string": {
          "query": "Ruan AND Yiming",
          "fields": ["name"]
        }
      }
    }
    
    
    POST users/_search
    {
      "query": {
        "simple_query_string": {
          "query": "Ruan Yiming",
          "fields": ["name"],
          "default_operator": "AND"
        }
      }
    }
    
    
    GET /movies/_search
    {
        "profile": true,
        "query":{
            "query_string":{
                "default_field": "title",
                "query": "Beafiful AND Mind"
            }
        }
    }
    
    
    # 多fields
    GET /movies/_search
    {
        "profile": true,
        "query":{
            "query_string":{
                "fields":[
                    "title",
                    "year"
                ],
                "query": "2012"
            }
        }
    }
    
    
    
    GET /movies/_search
    {
        "profile":true,
        "query":{
            "simple_query_string":{
                "query":"Beautiful +mind",
                "fields":["title"]
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:3.9-QueryString&SimpleQueryStrin

          本文链接:https://www.haomeiwen.com/subject/cfvtyhtx.html