Skip to content

Commit f72c060

Browse files
committed
Add index.queries.cache.enabled setting to IndexSettings
See elastic/elasticsearch#16268
1 parent e417401 commit f72c060

File tree

9 files changed

+111
-21
lines changed

9 files changed

+111
-21
lines changed

src/Nest/CommonAbstractions/DictionaryLike/IsADictionaryBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ public abstract class IsADictionaryBase<TKey, TValue> : IIsADictionary<TKey, TVa
1111
private IDictionary Self => BackingDictionary;
1212

1313
protected IsADictionaryBase() { this.BackingDictionary = new Dictionary<TKey, TValue>(); }
14-
//protected IsADictionaryBase(Dictionary<TKey, TValue> backingDictionary) { this.BackingDictionary = backingDictionary; }
14+
1515
protected IsADictionaryBase(IDictionary<TKey, TValue> backingDictionary)
1616
{
17-
this.BackingDictionary = backingDictionary != null
18-
? new Dictionary<TKey, TValue>(backingDictionary)
17+
this.BackingDictionary = backingDictionary != null
18+
? new Dictionary<TKey, TValue>(backingDictionary)
1919
: new Dictionary<TKey, TValue>();
2020
}
2121

@@ -79,4 +79,4 @@ public TValue this[TKey key]
7979
}
8080

8181

82-
}
82+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace Nest
2+
{
3+
public interface IQueriesCacheSettings
4+
{
5+
/// <summary>
6+
/// Whether the query cache is enabled. <c>True</c> by default.
7+
/// </summary>
8+
bool? Enabled { get; set; }
9+
}
10+
11+
public class QueriesCacheSettings : IQueriesCacheSettings
12+
{
13+
public bool? Enabled { get; set; }
14+
}
15+
16+
public class QueriesCacheSettingsDescriptor : DescriptorBase<QueriesCacheSettingsDescriptor, IQueriesCacheSettings>, IQueriesCacheSettings
17+
{
18+
bool? IQueriesCacheSettings.Enabled { get; set; }
19+
20+
/// <inheritdoc/>
21+
public QueriesCacheSettingsDescriptor Enabled(bool enabled = true) =>
22+
Assign(a => a.Enabled = enabled);
23+
}
24+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
3+
namespace Nest
4+
{
5+
public interface IQueriesSettings
6+
{
7+
IQueriesCacheSettings Cache { get; set; }
8+
}
9+
10+
public class QueriesSettings : IQueriesSettings
11+
{
12+
public IQueriesCacheSettings Cache { get; set; }
13+
}
14+
15+
public class QueriesSettingsDescriptor : DescriptorBase<QueriesSettingsDescriptor, IQueriesSettings>, IQueriesSettings
16+
{
17+
IQueriesCacheSettings IQueriesSettings.Cache { get; set; }
18+
19+
/// <inheritdoc/>
20+
public QueriesSettingsDescriptor Cache(Func<QueriesCacheSettingsDescriptor, IQueriesCacheSettings> selector) =>
21+
Assign(a => a.Cache = selector.Invoke(new QueriesCacheSettingsDescriptor()));
22+
}
23+
}

src/Nest/IndexModules/IndexSettings/Settings/DynamicIndexSettings.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,9 @@ public interface IDynamicIndexSettings : IIsADictionary<string, object>
9595

9696
public class DynamicIndexSettings : IsADictionaryBase<string, object>, IDynamicIndexSettings
9797
{
98-
public DynamicIndexSettings() : base() { }
98+
public DynamicIndexSettings() { }
99+
99100
public DynamicIndexSettings(IDictionary<string, object> container) : base(container) { }
100-
public DynamicIndexSettings(Dictionary<string, object> container)
101-
: base(container.Select(kv => kv).ToDictionary(kv => kv.Key, kv => kv.Value))
102-
{ }
103101

104102
/// <inheritdoc/>
105103
public int? NumberOfReplicas { get; set; }

src/Nest/IndexModules/IndexSettings/Settings/IndexSettings.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34

45
namespace Nest
@@ -7,8 +8,8 @@ namespace Nest
78
public interface IIndexSettings : IDynamicIndexSettings
89
{
910
/// <summary>
10-
/// The number of primary shards that an index should have. Defaults to 5.
11-
/// This setting can only be set at index creation time. It cannot be changed on a closed index.
11+
/// The number of primary shards that an index should have. Defaults to 5.
12+
/// This setting can only be set at index creation time. It cannot be changed on a closed index.
1213
/// </summary>
1314
int? NumberOfShards { get; set; }
1415

@@ -17,24 +18,27 @@ public interface IIndexSettings : IDynamicIndexSettings
1718
/// <para>EXPERT MODE toggle</para>
1819
/// </summary>
1920
FileSystemStorageImplementation? FileSystemStorageImplementation { get; set; }
21+
22+
/// <summary>
23+
/// Settings associated with queries.
24+
/// </summary>
25+
IQueriesSettings Queries { get; set; }
2026
}
2127

2228
/// <inheritdoc />
2329
public class IndexSettings: DynamicIndexSettings, IIndexSettings
2430
{
25-
public IndexSettings() : base() { }
31+
public IndexSettings() { }
2632
public IndexSettings(IDictionary<string, object> container) : base(container) { }
27-
public IndexSettings(Dictionary<string, object> container)
28-
: base(container.Select(kv => kv).ToDictionary(kv => kv.Key, kv => kv.Value))
29-
{ }
3033

3134
/// <inheritdoc />
3235
public int? NumberOfShards { get; set; }
3336

3437
/// <inheritdoc />
3538
public FileSystemStorageImplementation? FileSystemStorageImplementation { get; set; }
3639

37-
//public void Add(string setting, object value) => _backingDictionary.Add(setting, value);
40+
/// <inheritdoc />
41+
public IQueriesSettings Queries { get; set; }
3842
}
3943

4044
/// <inheritdoc />
@@ -50,6 +54,8 @@ public IndexSettingsDescriptor NumberOfShards(int? numberOfShards) =>
5054
public IndexSettingsDescriptor FileSystemStorageImplementation(FileSystemStorageImplementation? fs) =>
5155
Assign(a => a.FileSystemStorageImplementation = fs);
5256

57+
public IndexSettingsDescriptor Queries(Func<QueriesSettingsDescriptor, IQueriesSettings> selector) =>
58+
Assign(a => a.Queries = selector?.Invoke(new QueriesSettingsDescriptor()));
5359
}
5460

5561
}

src/Nest/IndexModules/IndexSettings/Settings/IndexSettingsConverter.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
7474
d[UpdatableIndexSettings.SlowlogIndexingLevel] = indexing?.LogLevel;
7575
d[UpdatableIndexSettings.SlowlogIndexingSource] = indexing?.Source;
7676

77-
7877
var indexSettings = value as IIndexSettings;
7978
d["index.number_of_shards"] = indexSettings?.NumberOfShards;
8079
d[UpdatableIndexSettings.NumberOfReplicas] = indexSettings?.NumberOfReplicas;
8180
d[UpdatableIndexSettings.StoreType] = indexSettings?.FileSystemStorageImplementation;
81+
d["index.queries.cache.enabled"] = indexSettings?.Queries?.Cache?.Enabled;
8282

8383
d[UpdatableIndexSettings.Analysis] = ds.Analysis;
8484

@@ -92,7 +92,7 @@ public JObject Flatten(JObject original, string prefix = "", JObject newObject =
9292
foreach (var property in original.Properties())
9393
{
9494
if (property.Value is JObject && property.Name != UpdatableIndexSettings.Analysis)
95-
Flatten(property.Value.Value<JObject>(), property.Name + ".", newObject);
95+
Flatten(property.Value.Value<JObject>(), prefix + property.Name + ".", newObject);
9696
else newObject.Add(prefix + property.Name, property.Value);
9797
}
9898
return newObject;
@@ -184,6 +184,10 @@ private void SetKnownIndexSettings(JsonReader reader, JsonSerializer serializer,
184184
Set<FileSystemStorageImplementation?>(s, settings, UpdatableIndexSettings.StoreType, v => s.FileSystemStorageImplementation = v,
185185
serializer);
186186

187+
var queries = s.Queries = new QueriesSettings();
188+
var queriesCache = s.Queries.Cache = new QueriesCacheSettings();
189+
Set<bool?>(s, settings, "index.queries.cache.enabled", v => queriesCache.Enabled = v);
190+
187191
IDictionary dict = s;
188192
foreach (var kv in settings)
189193
{

src/Nest/Nest.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,8 @@
607607
<Compile Include="IndexModules\IndexSettings\Merge\MergePolicySettings.cs" />
608608
<Compile Include="IndexModules\IndexSettings\Merge\MergeSchedulerSettings.cs" />
609609
<Compile Include="IndexModules\IndexSettings\Merge\MergeSettings.cs" />
610+
<Compile Include="IndexModules\IndexSettings\Queries\IQueriesCacheSettings.cs" />
611+
<Compile Include="IndexModules\IndexSettings\Queries\IQueriesSettings.cs" />
610612
<Compile Include="IndexModules\IndexSettings\Settings\DynamicIndexSettings.cs" />
611613
<Compile Include="IndexModules\IndexSettings\Settings\IndexSettings.cs" />
612614
<Compile Include="IndexModules\IndexSettings\Settings\IndexSettingsConverter.cs" />

src/Tests/IndexModules/IndexSettings/Settings/TypedIndexSettings.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class Usage : PromiseUsageTestBase<IIndexSettings, IndexSettingsDescripto
3232
{"index.unassigned.node_left.delayed_timeout", "1m" },
3333
{"index.number_of_shards", 1},
3434
{"index.store.type", "mmapfs"},
35+
{"index.queries.cache.enabled", true},
3536
};
3637

3738
/**
@@ -55,7 +56,8 @@ public class Usage : PromiseUsageTestBase<IIndexSettings, IndexSettingsDescripto
5556
.TotalShardsPerNode(10)
5657
.UnassignedNodeLeftDelayedTimeout(TimeSpan.FromMinutes(1))
5758
.RefreshInterval(-1)
58-
.FileSystemStorageImplementation(FileSystemStorageImplementation.MMap);
59+
.FileSystemStorageImplementation(FileSystemStorageImplementation.MMap)
60+
.Queries(q => q.Cache(c => c.Enabled()));
5961

6062
/**
6163
*/
@@ -81,7 +83,8 @@ public class Usage : PromiseUsageTestBase<IIndexSettings, IndexSettingsDescripto
8183
RoutingAllocationTotalShardsPerNode = 10,
8284
UnassignedNodeLeftDelayedTimeout = "1m",
8385
RefreshInterval = -1,
84-
FileSystemStorageImplementation = FileSystemStorageImplementation.MMap
86+
FileSystemStorageImplementation = FileSystemStorageImplementation.MMap,
87+
Queries = new QueriesSettings { Cache = new QueriesCacheSettings { Enabled = true } }
8588
};
8689
}
8790
}

src/Tests/Indices/IndexManagement/CreateIndex/CreateIndexApiTests.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using Elasticsearch.Net;
4+
using FluentAssertions;
45
using Nest;
56
using Tests.Framework;
67
using Tests.Framework.Integration;
@@ -30,6 +31,7 @@ protected override LazyResponses ClientUsage() => Calls(
3031
{
3132
{ "index.number_of_replicas", 1 },
3233
{ "index.number_of_shards", 1 },
34+
{ "index.queries.cache.enabled", true },
3335
}
3436
};
3537

@@ -39,15 +41,43 @@ protected override LazyResponses ClientUsage() => Calls(
3941
.Settings(s => s
4042
.NumberOfReplicas(1)
4143
.NumberOfShards(1)
44+
.Queries(q => q
45+
.Cache(c => c
46+
.Enabled()
47+
)
48+
)
4249
);
4350

4451
protected override CreateIndexRequest Initializer => new CreateIndexRequest(CallIsolatedValue)
4552
{
46-
Settings = new Nest.IndexSettings()
53+
Settings = new Nest.IndexSettings
4754
{
4855
NumberOfReplicas = 1,
4956
NumberOfShards = 1,
57+
Queries = new QueriesSettings
58+
{
59+
Cache = new QueriesCacheSettings
60+
{
61+
Enabled = true
62+
}
63+
}
5064
}
5165
};
66+
67+
protected override void ExpectResponse(ICreateIndexResponse response)
68+
{
69+
response.IsValid.Should().BeTrue();
70+
71+
var indexSettings = this.Client.GetIndexSettings(g => g.Index(CallIsolatedValue));
72+
73+
indexSettings.IsValid.Should().BeTrue();
74+
indexSettings.Indices.Should().NotBeEmpty().And.ContainKey(CallIsolatedValue);
75+
76+
var settings = indexSettings.Indices[CallIsolatedValue];
77+
78+
settings.Settings.NumberOfShards.Should().Be(1);
79+
settings.Settings.NumberOfReplicas.Should().Be(1);
80+
settings.Settings.Queries.Cache.Enabled.Should().Be(true);
81+
}
5282
}
5383
}

0 commit comments

Comments
 (0)