Class: JayAPI::Elasticsearch::QueryBuilder::QueryClauses::QueryString

Inherits:
QueryClause
  • Object
show all
Defined in:
lib/jay_api/elasticsearch/query_builder/query_clauses/query_string.rb

Overview

Represents a Query String query in Elasticsearch Documentation for this type of query can be found here: www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query:, fields: nil) ⇒ QueryString

Returns a new instance of QueryString.

Parameters:

  • fields (String, Array<String>) (defaults to: nil)

    The field or fields to search into.

  • query (String)

    The query string



21
22
23
24
# File 'lib/jay_api/elasticsearch/query_builder/query_clauses/query_string.rb', line 21

def initialize(query:, fields: nil)
  @fields = fields ? Array.wrap(fields) : nil
  @query = query
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



16
17
18
# File 'lib/jay_api/elasticsearch/query_builder/query_clauses/query_string.rb', line 16

def fields
  @fields
end

#queryObject (readonly)

Returns the value of attribute query.



16
17
18
# File 'lib/jay_api/elasticsearch/query_builder/query_clauses/query_string.rb', line 16

def query
  @query
end

Instance Method Details

#to_hHash

Returns The Hash that represents this query (in Elasticsearch’s format).

Returns:

  • (Hash)

    The Hash that represents this query (in Elasticsearch’s format)



28
29
30
31
32
33
34
# File 'lib/jay_api/elasticsearch/query_builder/query_clauses/query_string.rb', line 28

def to_h
  {
    query_string: {
      query: query
    }.merge(fields_attribute)
  }
end