使用AND运算符的基于Elasticsearch URI的查询

ram*_*ram 27 elasticsearch

如何在基于URI的查询中指定AND操作?我正在寻找类似的东西:

http://localhost:9200/_search?q="profiletype:student AND username:s*"
Run Code Online (Sandbox Code Playgroud)

dad*_*net 21

根据文档,它应该按照您的描述工作.见http://www.elasticsearch.org/guide/reference/query-dsl/query-string-query.html

也就是说,您还可以使用以下内容:

http://localhost:9200/_search?q="+profiletype:student +username:s*"
Run Code Online (Sandbox Code Playgroud)

  • 试试这个:curl localhost:9200/_search?q =%2Bprofiletype%3Astudent +%2Busername%3As* (2认同)

0x4*_*672 17

对于ElasticSearch中的URI搜索,您可以使用AND运算符profiletype:student AND username:s,如您所说,但不带引号:

  _search?q=profiletype:student AND username:s*
Run Code Online (Sandbox Code Playgroud)

您也可以将默认运算符设置为 AND

  _search?q=profiletype:student username:s*&default_operator=AND
Run Code Online (Sandbox Code Playgroud)

或者您可以使用+ 运算符来表示必须存在的术语,即可以将其 +profiletype:student +username:s用作查询字符串.但是,如果没有URL编码,这将不起作用.在URL编码+%2B和空间%20,因此替代方法是

  _search?q=%2Bprofiletype:student%20%2Busername:s*
Run Code Online (Sandbox Code Playgroud)


Nan*_*mar 5

您可以尝试以下行。

http://localhost:9200/_search?q=profiletype:student%20AND%20username:s*

http://localhost:9200/_search?q=profiletype:student AND username:s*
Run Code Online (Sandbox Code Playgroud)