Net core 2.1 elasticsearch working in development, it doesn't work in release

net core 2.1 elasticsearch working in development, it doesn't work in release,
this is my elasticsearch class

    {public static class ElasticsearchExtensions
    {
        public static void AddElasticsearch(
            this IServiceCollection services, IConfiguration configuration)
        {
            var defaultIndex ="honadonz";
           
       
            var settings = new ConnectionSettings(new Uri("https://711e0c87a+++++++=========dc2528152891.us-east-1.aws.found.io:9243"))
                .DefaultIndex(defaultIndex)
                .BasicAuthentication("elastic", "q1vqu++++++++yfV7RFS5WR6");

            // AddDefaultMappings(settings);

            var client = new ElasticClient(settings);

            services.AddSingleton<IElasticClient>(client);

            CreateIndex(client, defaultIndex);
        }

        private static void AddDefaultMappings(ConnectionSettings settings)
        {
            settings
                .DefaultMappingFor<ElasticSearchModel>(m => m);
                   
        }

        private static void CreateIndex(IElasticClient client, string indexName)
        {
            var createIndexResponse = client.CreateIndex("honadonz", c => c
                          .Mappings(m => m.Map<ElasticSearchModel>(mm => mm
                         .AutoMap()
                            ))
                            .RequestConfiguration(r => r
                            .DisableDirectStreaming()
    )
                  );

                   Console.WriteLine("Writeline is :" + createIndexResponse);
        }
    }
}

I use Elasticsearch version 6.8.1 in cloud.elastic.co and nest 6.8.0

What doesn't work? What exception or error do you get?

I am trying to find more error details, but now it only shows (status: 400, statusText: "Bad Request)

Take a look at the documentation about logging more details using OnRequestCompleted or a proxy, and making them available on DebugInformation

Error :

2019-07-28 09:54:38.745 +02:00 [Warning] Invalid NEST response built from a unsuccessful () low level call on POST: /honadon/_search?typed_keys=true

Audit trail of this API call:

OriginalException: System.Net.Http.HttpRequestException: An attempt was made to access a socket in a way forbidden by its access permissions ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions

at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
at System.Threading.Tasks.ValueTask1.get_Result() at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Threading.Tasks.ValueTask1.get_Result()
at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask1 creationTask) at System.Threading.Tasks.ValueTask1.get_Result()
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.FinishSendAsyncUnbuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
at Elasticsearch.Net.HttpConnection.Request[TResponse](RequestData requestData)

I wrote to support, company which I take hosting plan, and they answer to me

Dear Customer,

The issue is due to your website calls an external API.Please use "Outgoing Port" to open the connection for this API.
https://www.smarterasp.net/support/kb/a1916/how-to-enable-outgoing-port-from-your-hosting-control-panel.aspx?KBSearchID=592490

Thank you.
Ilysokhuja:
why i need this, i havent problem with AWS, why same service from cloud.elastic.co has error like this, why i should change something, if tomorrow i change my elastic to another cloud , should i change everytime, i think this is not good solution

Joy (staff)
7/28/2019 4:47:46 AM Dear Customer,

For security reason, we only allow 80 and 443 ports to third party server. If you are using different ports to connect to third party service, you will need to open outgoing port from our server to the specific server port.

If you changed the third party server to another one in the further, you will then need update your outgoing port setting to the new server ip.

Thank you.

Dear Customer,

You will need to upgrade your hosting account to our .net premium plan, so you can enable spacial port to the remote server.

Thank you.

Why cloud.elastic.co cant work like AWS?

I don't know what is meant by this statement. There are many differences between Elastic's Elasticsearch Service and AWS.

It sounds like the issue is related to your hosting provider not allowing outbound connections on port 9243, which should be configurable on the hosting provider. Note that port 443 is also supported for HTTPS.

Now its working , after enabled port from hosting provider.

Today I changed my account cloud.elastic.co(I am using different URL), I didnt change any code for search, and create new index same version as before (v7.1.1), but i have unexpectedly error

2019-08-06 22:56:40.131 +05:00 [Warning] Invalid NEST response built from a unsuccessful (400) low level call on POST: /atiruz/_search?typed_keys=true

Audit trail of this API call:

  • [1] BadResponse: Node: https://f87fd4280a7944--------cd160f6f03ee54.europe-west1.gcp.cloud.es.io:9243/ Took: 00:00:00.1334420

OriginalException: Elasticsearch.Net.ElasticsearchClientException: Request failed to execute. Call: Status code 400 from: POST /atiruz/_search?typed_keys=true. ServerError: Type: search_phase_execution_exception Reason: "all shards failed"

Request:

{"from":0,"query":{"bool":{"filter":[{"geo_bounding_box":{"_name":"Location","boost":1.1,"location":{"bottom_right":{"lat":41.23020955415123,"lon":69.34550008544922},"top_left":{"lat":41.368716908561794,"lon":69.13469991455077}}}]},"size":26,"sort":[{"createdDate":{"order":"desc"}}]}

Response:

{"error":{"root_cause":[{"type":"query_shard_exception","reason":"failed to find geo_point field [location]","index_uuid":"01aoWJJfSeSLyhgXJX-uIg","index":"atiruz"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"atiruz","node":"RELnlMkQRVWY5BXnJ91ngw","reason":{"type":"query_shard_exception","reason":"failed to find geo_point field [location]","index_uuid":"01aoWJJfSeSLyhgXJX-uIg","index":"atiruz"}}]},"status":400}

How can i fix this?

This would be better to open as a New topic, since it's not related to the original topic.

It looks like the mapping either does not have a location field, or the location field is not mapped as a geo_point. Check the mapping in the index; if it's incorrect, you'll need to reindex, and if it's not there, you can add it to the index.