Skip to content

Commit 9dbece3

Browse files
committed
handle post typeless indices mappings on analysis
closes #412
1 parent 5317ddd commit 9dbece3

File tree

2 files changed

+42
-43
lines changed

2 files changed

+42
-43
lines changed

app/models/analysis/IndexFields.scala

+9-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ object IndexFields {
1414

1515
def apply(index: String, data: JsValue) = {
1616
val docTypes = (data \ index \ "mappings").as[JsObject].keys
17-
val fields = docTypes.flatMap { docType =>
18-
extractProperties((data \ index \ "mappings" \ docType \ "properties").as[JsValue])
19-
}.toSeq
20-
JsArray(fields.map(JsString(_)))
17+
val fields = if (docTypes.size == 1 && docTypes.head == "properties") {
18+
extractProperties((data \ index \ "mappings" \ "properties").as[JsValue])
19+
} else { // FIXME: ES < 7
20+
docTypes.flatMap { docType =>
21+
extractProperties((data \ index \ "mappings" \ docType \ "properties").as[JsValue])
22+
}.toSeq
23+
}
24+
25+
JsArray(fields.map(JsString))
2126
}
2227

2328
def extractProperties(data: JsValue): Seq[String] = {

test/models/analysis/IndexFieldsSpec.scala

+33-39
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object IndexFieldsSpec extends Specification {
99
s2"""
1010
IndexField should
1111
should return only string fields $regularFields
12-
should return fields from all types $multipleTypes
12+
should return fields from all types $multipleTypes FIXME < 7
1313
should return sub fields on multi fields fields $multiFields
1414
should return properties of object fields $objects
1515

@@ -21,18 +21,16 @@ object IndexFieldsSpec extends Specification {
2121
|{
2222
| "index_name": {
2323
| "mappings": {
24-
| "type_1": {
25-
| "properties": {
26-
| "regular_field": {
27-
| "type": "string"
28-
| },
29-
| "regular_field_2": {
30-
| "type": "string",
31-
| "analyzer": "standard"
32-
| },
33-
| "ignored_field": {
34-
| "type": "integer"
35-
| }
24+
| "properties": {
25+
| "regular_field": {
26+
| "type": "string"
27+
| },
28+
| "regular_field_2": {
29+
| "type": "string",
30+
| "analyzer": "standard"
31+
| },
32+
| "ignored_field": {
33+
| "type": "integer"
3634
| }
3735
| }
3836
| }
@@ -78,17 +76,15 @@ object IndexFieldsSpec extends Specification {
7876
|{
7977
| "index_name": {
8078
| "mappings": {
81-
| "type_1": {
82-
| "properties": {
83-
| "multi_field": {
84-
| "type": "string",
85-
| "fields": {
86-
| "sub_field": {
87-
| "type": "string"
88-
| },
89-
| "ignored_sub_field": {
90-
| "type": "integer"
91-
| }
79+
| "properties": {
80+
| "multi_field": {
81+
| "type": "string",
82+
| "fields": {
83+
| "sub_field": {
84+
| "type": "string"
85+
| },
86+
| "ignored_sub_field": {
87+
| "type": "integer"
9288
| }
9389
| }
9490
| }
@@ -108,22 +104,20 @@ object IndexFieldsSpec extends Specification {
108104
|{
109105
| "index_name": {
110106
| "mappings": {
111-
| "type_1": {
112-
| "properties": {
113-
| "object_type": {
114-
| "properties": {
115-
| "first_level_property": {
116-
| "properties": {
117-
| "second_level_property": {
118-
| "type": "string"
119-
| }
107+
| "properties": {
108+
| "object_type": {
109+
| "properties": {
110+
| "first_level_property": {
111+
| "properties": {
112+
| "second_level_property": {
113+
| "type": "string"
120114
| }
121-
| },
122-
| "first_level_property_2": {
123-
| "properties": {
124-
| "second_level_property": {
125-
| "type": "string"
126-
| }
115+
| }
116+
| },
117+
| "first_level_property_2": {
118+
| "properties": {
119+
| "second_level_property": {
120+
| "type": "string"
127121
| }
128122
| }
129123
| }

0 commit comments

Comments
 (0)