logstash-plugins / logstash-filter-elasticsearch

Elasticsearch filter for Logstash
Apache License 2.0
21 stars 83 forks source link

set @query_dsl parameter directly , without using query_template file #114

Open al-ah opened 5 years ago

al-ah commented 5 years ago

i need set @query_dsl parameter directly , without using query_template like this :

elasticsearch {    
        hosts => "localhost:9200"
        index => ".ml-anomalies-*"
            query_dsl => '{
                 "size": 20, 
          "query": {
            "bool": {
              "filter": [
                {
                  "range": {
                    "record_score": {
                      "gte": %{[my_field]}
                    }
                  }
                },
                .
                .
                .
                .
              ]
            }
          },
          "sort": [
            {
              "record_score": {
                "order": "desc"
              }
            }
          ],
          "_source": [
            "job_id",
            .
            .
            .
          ]
                }'
al-ah commented 5 years ago

can change/add this to elasticsearch.rb :


  # elasticsearch query in DSL format.
  config :query_dsl, :validate => :string , :default => nil

  def register
    @clients_pool = java.util.concurrent.ConcurrentHashMap.new

    #Load query if it exists
    #if @query_template changed to this :
    if @query_dsl.nil? && @query_template
      .....
  end # def register