Skip to content

Commit

Permalink
Make typeless APIs usable with indices whose type name is different f…
Browse files Browse the repository at this point in the history
…rom `_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
  • Loading branch information
jpountz committed Dec 4, 2018
1 parent 8ccb466 commit d24b40f
Show file tree
Hide file tree
Showing 36 changed files with 747 additions and 113 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
"bulk without types on an index that has types":

- skip:
version: " - 6.99.99"
reason: Typeless APIs were introduced in 7.0.0

- do:
indices.create: # not using include_type_name: false on purpose
index: index
body:
mappings:
not_doc:
properties:
foo:
type: "keyword"
- do:
bulk:
refresh: true
body:
- index:
_index: index
_id: 0
- foo: bar
- index:
_index: index
_id: 1
- foo: bar

- do:
count:
index: index

- match: {count: 2}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
"DELETE with typeless API on an index that has types":

- skip:
version: " - 6.99.99"
reason: Typeless APIs were introduced in 7.0.0

- do:
indices.create: # not using include_type_name: false on purpose
index: index
body:
mappings:
not_doc:
properties:
foo:
type: "keyword"

- do:
index:
index: index
type: not_doc
id: 1
body: { foo: bar }

- do:
catch: bad_request
delete:
index: index
type: some_random_type
id: 1

- match: { error.root_cause.0.reason: "/Rejecting.mapping.update.to.\\[index\\].as.the.final.mapping.would.have.more.than.1.type.*/" }

- do:
delete:
index: index
id: 1

- match: { _index: "index" }
- match: { _type: "_doc" }
- match: { _id: "1"}
- match: { _version: 2}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
"Explain with typeless API on an index that has types":

- skip:
version: " - 6.99.99"
reason: Typeless APIs were introduced in 7.0.0

- do:
indices.create: # not using include_type_name: false on purpose
index: index
body:
mappings:
not_doc:
properties:
foo:
type: "keyword"

- do:
index:
index: index
type: not_doc
id: 1
body: { foo: bar }

- do:
indices.refresh: {}

- do:
catch: missing
explain:
index: index
type: some_random_type
id: 1
body:
query:
match_all: {}

- match: { _index: "index" }
- match: { _type: "some_random_type" }
- match: { _id: "1"}
- match: { matched: false}

- do:
explain:
index: index
type: _doc #todo: make _explain typeless and remove this
id: 1
body:
query:
match_all: {}

- match: { _index: "index" }
- match: { _type: "_doc" }
- match: { _id: "1"}
- is_true: matched
- match: { explanation.value: 1 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
"GET with typeless API on an index that has types":

- skip:
version: " - 6.99.99"
reason: Typeless APIs were introduced in 7.0.0

- do:
indices.create: # not using include_type_name: false on purpose
index: index
body:
mappings:
not_doc:
properties:
foo:
type: "keyword"

- do:
index:
index: index
type: not_doc
id: 1
body: { foo: bar }

- do:
catch: missing
get:
index: index
type: some_random_type
id: 1

- match: { _index: "index" }
- match: { _type: "some_random_type" }
- match: { _id: "1"}
- match: { found: false}

- do:
get:
index: index
id: 1

- match: { _index: "index" }
- match: { _type: "_doc" }
- match: { _id: "1"}
- match: { _version: 1}
- match: { _source: { foo: bar }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
"Index with typeless API on an index that has types":

- skip:
version: " - 6.99.99"
reason: Typeless APIs were introduced in 7.0.0

- do:
indices.create: # not using include_type_name: false on purpose
index: index
body:
mappings:
not_doc:
properties:
foo:
type: "keyword"

- do:
index:
index: index
id: 1
body: { foo: bar }

- match: { _index: "index" }
- match: { _type: "_doc" }
- match: { _id: "1"}
- match: { _version: 1}

- do:
get: # not using typeless API on purpose
index: index
type: not_doc
id: 1

- match: { _index: "index" }
- match: { _type: "not_doc" } # the important bit to check
- match: { _id: "1"}
- match: { _version: 1}
- match: { _source: { foo: bar }}


- do:
index:
index: index
body: { foo: bar }

- match: { _index: "index" }
- match: { _type: "_doc" }
- match: { _version: 1}
- set: { _id: id }

- do:
get: # using typeful API on purpose
index: index
type: not_doc
id: '$id'

- match: { _index: "index" }
- match: { _type: "not_doc" } # the important bit to check
- match: { _id: $id}
- match: { _version: 1}
- match: { _source: { foo: bar }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
"GET mapping with typeless API on an index that has types":

- skip:
version: " - 6.99.99"
reason: include_type_name was introduced in 7.0.0

- do:
indices.create: # not using include_type_name: false on purpose
index: index
body:
mappings:
not_doc:
properties:
foo:
type: "keyword"

- do:
indices.get_mapping:
include_type_name: false
index: index

- match: { index.mappings.properties.foo.type: "keyword" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
"PUT mapping with typeless API on an index that has types":

- skip:
version: " - 6.99.99"
reason: include_type_name was introduced in 7.0.0

- do:
indices.create: # not using include_type_name: false on purpose
index: index
body:
mappings:
not_doc:
properties:
foo:
type: "keyword"

- do:
indices.put_mapping:
include_type_name: false
index: index
body:
properties:
bar:
type: "long"

- do:
indices.get_mapping:
include_type_name: false
index: index

- match: { index.mappings.properties.foo.type: "keyword" }
- match: { index.mappings.properties.bar.type: "long" }

- do:
indices.put_mapping:
include_type_name: false
index: index
body:
properties:
foo:
type: "keyword" # also test no-op updates that trigger special logic wrt the mapping version

- do:
catch: bad_request
indices.put_mapping:
index: index
body:
some_other_type:
properties:
bar:
type: "long"
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
"mtermvectors without types on an index that has types":

- skip:
version: " - 6.99.99"
reason: Typeless APIs were introduced in 7.0.0

- do:
indices.create: # not using include_type_name: false on purpose
index: index
body:
mappings:
not_doc:
properties:
foo:
type : "text"
term_vector : "with_positions_offsets"

- do:
index:
index: index
id: 1
body: { foo: bar }

- do:
mtermvectors:
body:
docs:
- _index: index
_id: 1

- match: {docs.0.term_vectors.foo.terms.bar.term_freq: 1}
Loading

0 comments on commit d24b40f

Please sign in to comment.