Elasticsearch URI based query with AND operator

后端 未结 4 1408
一向
一向 2021-01-31 09:00

How do I specify AND operation in URI based query? I\'m looking for something like:

http://localhost:9200/_search?q=\"profiletype:student AND username:s*\"


        
相关标签:
4条回答
  • 2021-01-31 09:49

    According to documentation, it should work as you described it. See http://www.elasticsearch.org/guide/reference/query-dsl/query-string-query.html

    That said, you can also use the following:

    http://localhost:9200/_search?q="+profiletype:student +username:s*"
    
    0 讨论(0)
  • 2021-01-31 09:53

    For URI search in ElasticSearch, you can use either the AND operator profiletype:student AND username:s, as you say but without quotes:

      _search?q=profiletype:student AND username:s*
    

    You can also set the default operator to AND

      _search?q=profiletype:student username:s*&default_operator=AND
    

    Or you can use the + operator for terms that must be present, i.e. one would use +profiletype:student +username:s as query string. This doesn't work without URL encoding, though. In URL encoding + is %2Band space is %20, therefore the alternative would be

      _search?q=%2Bprofiletype:student%20%2Busername:s*
    
    0 讨论(0)
  • 2021-01-31 09:59

    You can try bellow line.

    http://localhost:9200/_search?q=profiletype:student%20AND%20username:s*
    
    http://localhost:9200/_search?q=profiletype:student AND username:s*
    
    0 讨论(0)
  • 2021-01-31 10:00

    i had to combine the default operator and + sign to make it work

    curl -XGET 'localhost:9200/apm/inventory/_search?default_operator=AND&q=tenant_id:t2+_all:node_1'
    
    0 讨论(0)
提交回复
热议问题