Skip to content

Commit d24b40f

Browse files
authored
Make typeless APIs usable with indices whose type name is different from _doc (#35790)
This commit makes `document`, `update`, `explain`, `termvectors` and `mapping` typeless APIs work on indices that have a type whose name is not `_doc`. Unfortunately, this needs to be a bit of a hack since I didn't want calls with random type names to see documents with the type name that the user had chosen upon type creation. The `explain` and `termvectors` do not support being called without a type for now so the test is just using `_doc` as a type for now, we will need to fix tests later but this shouldn't require further changes server-side since passing `_doc` as a type name is what typeless APIs do internally anyway. Relates #35190
1 parent 8ccb466 commit d24b40f

36 files changed

+747
-113
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
"bulk without types on an index that has types":
3+
4+
- skip:
5+
version: " - 6.99.99"
6+
reason: Typeless APIs were introduced in 7.0.0
7+
8+
- do:
9+
indices.create: # not using include_type_name: false on purpose
10+
index: index
11+
body:
12+
mappings:
13+
not_doc:
14+
properties:
15+
foo:
16+
type: "keyword"
17+
- do:
18+
bulk:
19+
refresh: true
20+
body:
21+
- index:
22+
_index: index
23+
_id: 0
24+
- foo: bar
25+
- index:
26+
_index: index
27+
_id: 1
28+
- foo: bar
29+
30+
- do:
31+
count:
32+
index: index
33+
34+
- match: {count: 2}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
"DELETE with typeless API on an index that has types":
3+
4+
- skip:
5+
version: " - 6.99.99"
6+
reason: Typeless APIs were introduced in 7.0.0
7+
8+
- do:
9+
indices.create: # not using include_type_name: false on purpose
10+
index: index
11+
body:
12+
mappings:
13+
not_doc:
14+
properties:
15+
foo:
16+
type: "keyword"
17+
18+
- do:
19+
index:
20+
index: index
21+
type: not_doc
22+
id: 1
23+
body: { foo: bar }
24+
25+
- do:
26+
catch: bad_request
27+
delete:
28+
index: index
29+
type: some_random_type
30+
id: 1
31+
32+
- match: { error.root_cause.0.reason: "/Rejecting.mapping.update.to.\\[index\\].as.the.final.mapping.would.have.more.than.1.type.*/" }
33+
34+
- do:
35+
delete:
36+
index: index
37+
id: 1
38+
39+
- match: { _index: "index" }
40+
- match: { _type: "_doc" }
41+
- match: { _id: "1"}
42+
- match: { _version: 2}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
"Explain with typeless API on an index that has types":
3+
4+
- skip:
5+
version: " - 6.99.99"
6+
reason: Typeless APIs were introduced in 7.0.0
7+
8+
- do:
9+
indices.create: # not using include_type_name: false on purpose
10+
index: index
11+
body:
12+
mappings:
13+
not_doc:
14+
properties:
15+
foo:
16+
type: "keyword"
17+
18+
- do:
19+
index:
20+
index: index
21+
type: not_doc
22+
id: 1
23+
body: { foo: bar }
24+
25+
- do:
26+
indices.refresh: {}
27+
28+
- do:
29+
catch: missing
30+
explain:
31+
index: index
32+
type: some_random_type
33+
id: 1
34+
body:
35+
query:
36+
match_all: {}
37+
38+
- match: { _index: "index" }
39+
- match: { _type: "some_random_type" }
40+
- match: { _id: "1"}
41+
- match: { matched: false}
42+
43+
- do:
44+
explain:
45+
index: index
46+
type: _doc #todo: make _explain typeless and remove this
47+
id: 1
48+
body:
49+
query:
50+
match_all: {}
51+
52+
- match: { _index: "index" }
53+
- match: { _type: "_doc" }
54+
- match: { _id: "1"}
55+
- is_true: matched
56+
- match: { explanation.value: 1 }
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
"GET with typeless API on an index that has types":
3+
4+
- skip:
5+
version: " - 6.99.99"
6+
reason: Typeless APIs were introduced in 7.0.0
7+
8+
- do:
9+
indices.create: # not using include_type_name: false on purpose
10+
index: index
11+
body:
12+
mappings:
13+
not_doc:
14+
properties:
15+
foo:
16+
type: "keyword"
17+
18+
- do:
19+
index:
20+
index: index
21+
type: not_doc
22+
id: 1
23+
body: { foo: bar }
24+
25+
- do:
26+
catch: missing
27+
get:
28+
index: index
29+
type: some_random_type
30+
id: 1
31+
32+
- match: { _index: "index" }
33+
- match: { _type: "some_random_type" }
34+
- match: { _id: "1"}
35+
- match: { found: false}
36+
37+
- do:
38+
get:
39+
index: index
40+
id: 1
41+
42+
- match: { _index: "index" }
43+
- match: { _type: "_doc" }
44+
- match: { _id: "1"}
45+
- match: { _version: 1}
46+
- match: { _source: { foo: bar }}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
"Index with typeless API on an index that has types":
3+
4+
- skip:
5+
version: " - 6.99.99"
6+
reason: Typeless APIs were introduced in 7.0.0
7+
8+
- do:
9+
indices.create: # not using include_type_name: false on purpose
10+
index: index
11+
body:
12+
mappings:
13+
not_doc:
14+
properties:
15+
foo:
16+
type: "keyword"
17+
18+
- do:
19+
index:
20+
index: index
21+
id: 1
22+
body: { foo: bar }
23+
24+
- match: { _index: "index" }
25+
- match: { _type: "_doc" }
26+
- match: { _id: "1"}
27+
- match: { _version: 1}
28+
29+
- do:
30+
get: # not using typeless API on purpose
31+
index: index
32+
type: not_doc
33+
id: 1
34+
35+
- match: { _index: "index" }
36+
- match: { _type: "not_doc" } # the important bit to check
37+
- match: { _id: "1"}
38+
- match: { _version: 1}
39+
- match: { _source: { foo: bar }}
40+
41+
42+
- do:
43+
index:
44+
index: index
45+
body: { foo: bar }
46+
47+
- match: { _index: "index" }
48+
- match: { _type: "_doc" }
49+
- match: { _version: 1}
50+
- set: { _id: id }
51+
52+
- do:
53+
get: # using typeful API on purpose
54+
index: index
55+
type: not_doc
56+
id: '$id'
57+
58+
- match: { _index: "index" }
59+
- match: { _type: "not_doc" } # the important bit to check
60+
- match: { _id: $id}
61+
- match: { _version: 1}
62+
- match: { _source: { foo: bar }}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
"GET mapping with typeless API on an index that has types":
3+
4+
- skip:
5+
version: " - 6.99.99"
6+
reason: include_type_name was introduced in 7.0.0
7+
8+
- do:
9+
indices.create: # not using include_type_name: false on purpose
10+
index: index
11+
body:
12+
mappings:
13+
not_doc:
14+
properties:
15+
foo:
16+
type: "keyword"
17+
18+
- do:
19+
indices.get_mapping:
20+
include_type_name: false
21+
index: index
22+
23+
- match: { index.mappings.properties.foo.type: "keyword" }
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
"PUT mapping with typeless API on an index that has types":
3+
4+
- skip:
5+
version: " - 6.99.99"
6+
reason: include_type_name was introduced in 7.0.0
7+
8+
- do:
9+
indices.create: # not using include_type_name: false on purpose
10+
index: index
11+
body:
12+
mappings:
13+
not_doc:
14+
properties:
15+
foo:
16+
type: "keyword"
17+
18+
- do:
19+
indices.put_mapping:
20+
include_type_name: false
21+
index: index
22+
body:
23+
properties:
24+
bar:
25+
type: "long"
26+
27+
- do:
28+
indices.get_mapping:
29+
include_type_name: false
30+
index: index
31+
32+
- match: { index.mappings.properties.foo.type: "keyword" }
33+
- match: { index.mappings.properties.bar.type: "long" }
34+
35+
- do:
36+
indices.put_mapping:
37+
include_type_name: false
38+
index: index
39+
body:
40+
properties:
41+
foo:
42+
type: "keyword" # also test no-op updates that trigger special logic wrt the mapping version
43+
44+
- do:
45+
catch: bad_request
46+
indices.put_mapping:
47+
index: index
48+
body:
49+
some_other_type:
50+
properties:
51+
bar:
52+
type: "long"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
"mtermvectors without types on an index that has types":
3+
4+
- skip:
5+
version: " - 6.99.99"
6+
reason: Typeless APIs were introduced in 7.0.0
7+
8+
- do:
9+
indices.create: # not using include_type_name: false on purpose
10+
index: index
11+
body:
12+
mappings:
13+
not_doc:
14+
properties:
15+
foo:
16+
type : "text"
17+
term_vector : "with_positions_offsets"
18+
19+
- do:
20+
index:
21+
index: index
22+
id: 1
23+
body: { foo: bar }
24+
25+
- do:
26+
mtermvectors:
27+
body:
28+
docs:
29+
- _index: index
30+
_id: 1
31+
32+
- match: {docs.0.term_vectors.foo.terms.bar.term_freq: 1}

0 commit comments

Comments
 (0)