简体   繁体   English

Lucene样式查询字符串Elasticsearch PHP

[英]Lucene-Style query string Elasticsearch PHP

I have searched for days how to query data from Elasticsearch with an array as parameter or with JSON formaat like showing on this page http://www.elasticsearch.org/guide/en/elasticsearch/client/php-api/current/_quickstart.html But not with a lucene-style query string. 我已经搜寻了几天如何使用数组作为参数或使用JSON格式从Elasticsearch查询数据,如此页面上所示http://www.elasticsearch.org/guide/en/elasticsearch/client/php-api/current/_quickstart .html,但不包含Lucene样式的查询字符串。 Is there any way to query data from Elasticsearch using lucene-style query string with Elasticsearch PHP Client API, like (type:apache-access OR type:apache-error)? 有什么方法可以通过Elasticsearch PHP Client API使用Lucene样式的查询字符串从Elasticsearch查询数据,例如(type:apache-access或type:apache-error)?

I believe that you can do this via the Elasticsearch basic query via uri: 我相信您可以通过uri通过Elasticsearch基本查询来做到这一点:

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-uri-request.html http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-uri-request.html

curl -XGET 'http://localhost:9200/twitter/tweet/_search?q=user:kimchy'

A bit of discussion on it (including the fact that it supports Lucene style queries) here: 在此处进行一些讨论(包括它支持Lucene样式查询的事实):

http://okfnlabs.org/blog/2013/07/01/elasticsearch-query-tutorial.html http://okfnlabs.org/blog/2013/07/01/elasticsearch-query-tutorial.html

Querying Basic Queries Using Only the Query String 仅使用查询字符串查询基本查询

Basic queries can be done using only query string parameters in the URL. 基本查询只能使用URL中的查询字符串参数来完成。 For example, the following searches for text 'hello' in any field in any document and returns at most 5 results: 例如,以下在任何文档的任何字段中搜索文本“ hello”,并最多返回5个结果:

{endpoint}/_search?q=hello&size=5

Basic queries like this have the advantage that they only involve accessing a URL and thus, for example, can be performed just using any web browser. 这样的基本查询的优势在于,它们仅涉及访问URL,因此例如可以仅使用任何Web浏览器执行。 However, this method is limited and does not give you access to most of the more powerful query features. 但是,此方法是有限的,不能让您访问大多数更强大的查询功能。

Basic queries use the q query string parameter which supports the Lucene query parser syntax and hence filters on specific fields (eg fieldname:value), wildcards (eg abc*) and more. 基本查询使用q查询字符串参数,该参数支持Lucene查询解析器语法,因此可对特定字段(例如fieldname:value),通配符(例如abc *)等进行过滤。

There are a variety of other options (eg size, from etc) that you can also specify to customize the query and its results. 您还可以指定多种其他选项(例如大小,来源等)以自定义查询及其结果。 Full details can be found in the ElasticSearch URI request docs. 完整的详细信息可以在ElasticSearch URI请求文档中找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM