olivere / elastic

Deprecated: Use the official Elasticsearch client for Go at https://github.com/elastic/go-elasticsearch
https://olivere.github.io/elastic/
MIT License
7.39k stars 1.15k forks source link

elastic v6 not work correctly with http proxy #1672

Open ermazi opened 1 year ago

ermazi commented 1 year ago

Which version of Elastic are you using?

[x] elastic.v6 (for Elasticsearch 6.x)

Please describe the expected behavior

client with http proxy should work well.

Please describe the actual behavior

but all settings are omitted

Any steps to reproduce the behavior?

    proxyUrl, _ := url.Parse("http://proxyIP1:48888")

    client, err := elastic.NewClient(
        elastic.SetURL("http://esNode01:9200"),
        elastic.SetSniff(false),
        elastic.SetHttpClient(
            &http.Client{
                Transport: &http.Transport{
                    MaxIdleConnsPerHost: 10,
                    Proxy:               http.ProxyURL(proxyUrl),
                },
                Timeout: 10 * time.Second,
            }),
    )

    if err != nil {
        log.Printf("err: %v", err)
        return
    }

    query := elastic.NewBoolQuery()
    termQuery := elastic.NewTermQuery("term1", "termValue1")
    rangeQuery := elastic.NewRangeQuery("@timestamp").Gte(time.Now().Add(-48 * time.Hour)).Lte(time.Now().Add(-24 * time.Hour))

    query = query.Must(termQuery, rangeQuery)

    searchResult, err := client.Search().
        Index("index01*").
        Query(query).
        From(0).Size(1).
        Pretty(true).
        Do(context.Background())

    if err != nil {
        log.Printf("search err: %v", err)
        return
    }

    log.Printf("%+v", len(searchResult.Hits.Hits))

result should be 1, but 10

it seems that not condition passed when use Proxy~