Elasticsearch URI based query with AND operator

后端 未结 4 1413
一向
一向 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: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*
    

提交回复
热议问题