<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using Elasticsearch.Net;
using FluentAssertions;
using Nest;
using Tests.Framework;
using Tests.Framework.Integration;
using Tests.Framework.MockData;
using Xunit;
using static Nest.Infer;

namespace Tests.Document.Multiple.UpdateByQuery
{
	[Collection(IntegrationContext.OwnIndex)]
	public class UpdateByQueryApiTests : ApiIntegrationTestBase<IUpdateByQueryResponse, IUpdateByQueryRequest, UpdateByQueryDescriptor<UpdateByQueryApiTests.Test>, UpdateByQueryRequest>
	{
		public class Test
		{
			public string Text { get; set; }
			public string Flag { get; set; }
		}

		public UpdateByQueryApiTests(OwnIndexCluster cluster, EndpointUsage usage) : base(cluster, usage) { }

		protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
		{
			foreach (var index in values.Values)
			{
				this.Client.CreateIndex(index, c => c
					.Mappings(m => m
						.Map<Test>(map => map
							.Dynamic(false)
							.Properties(props => props
								.String(s => s.Name(p => p.Text))
							)
						)
					)
				);
				this.Client.Index(new Test { Text = "words words", Flag = "bar" }, i=>i.Index(index).Refresh());
				this.Client.Index(new Test { Text = "words words", Flag = "foo" }, i=>i.Index(index).Refresh());
				this.Client.Map<Test>(m => m
					.Index(index)
					.Properties(props => props
						.String(s => s.Name(p => p.Text))
						.String(s => s.Name(p => p.Flag).Analyzer("keyword"))
					)
				);

				var searchResults = this.SearchFlags(index);
				searchResults.Total.Should().Be(0);
			}
		}
		protected override LazyResponses ClientUsage() => Calls(
			fluent: (client, f) => client.UpdateByQuery(CallIsolatedValue, Type<Test>(), f),
			fluentAsync: (client, f) => client.UpdateByQueryAsync(CallIsolatedValue, Type<Test>(), f),
			request: (client, r) => client.UpdateByQuery(r),
			requestAsync: (client, r) => client.UpdateByQueryAsync(r)
		);
		protected override void OnAfterCall(IElasticClient client) => client.Refresh(CallIsolatedValue);

		protected override bool ExpectIsValid => true;
		protected override int ExpectStatusCode => 200;<commit_msg>Fix failing update by query tests due to string mapping<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using Elasticsearch.Net;
using FluentAssertions;
using Nest;
using Tests.Framework;
using Tests.Framework.Integration;
using Tests.Framework.MockData;
using Xunit;
using static Nest.Infer;

namespace Tests.Document.Multiple.UpdateByQuery
{
	[Collection(IntegrationContext.OwnIndex)]
	public class UpdateByQueryApiTests : ApiIntegrationTestBase<IUpdateByQueryResponse, IUpdateByQueryRequest, UpdateByQueryDescriptor<UpdateByQueryApiTests.Test>, UpdateByQueryRequest>
	{
		public class Test
		{
			public string Text { get; set; }
			public string Flag { get; set; }
		}

		public UpdateByQueryApiTests(OwnIndexCluster cluster, EndpointUsage usage) : base(cluster, usage) { }

		protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
		{
			foreach (var index in values.Values)
			{
				this.Client.CreateIndex(index, c => c
					.Mappings(m => m
						.Map<Test>(map => map
							.Dynamic(false)
							.Properties(props => props
								.String(s => s.Name(p => p.Text))
							)
						)
					)
				);
				this.Client.Index(new Test { Text = "words words", Flag = "bar" }, i=>i.Index(index).Refresh());
				this.Client.Index(new Test { Text = "words words", Flag = "foo" }, i=>i.Index(index).Refresh());
				this.Client.Map<Test>(m => m
					.Index(index)
					.Properties(props => props
						.Text(s => s.Name(p => p.Text))
						.Keyword(s => s.Name(p => p.Flag))
					)
				);

				var searchResults = this.SearchFlags(index);
				searchResults.Total.Should().Be(0);
			}
		}
		protected override LazyResponses ClientUsage() => Calls(
			fluent: (client, f) => client.UpdateByQuery(CallIsolatedValue, Type<Test>(), f),
			fluentAsync: (client, f) => client.UpdateByQueryAsync(CallIsolatedValue, Type<Test>(), f),
			request: (client, r) => client.UpdateByQuery(r),
			requestAsync: (client, r) => client.UpdateByQueryAsync(r)
		);
		protected override void OnAfterCall(IElasticClient client) => client.Refresh(CallIsolatedValue);

		protected override bool ExpectIsValid => true;
		protected override int ExpectStatusCode => 200;
{'fraction_non_alphanumeric': 0.1296422875370244, 'fraction_numerical': 0.001822738664843928, 'mean_word_length': 4.1345029239766085, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '375176', 'n_tokens_mistral': 1597, 'n_tokens_neox': 1340, 'n_words': 308}