Skip to content

Commit

Permalink
handle post typeless indices mappings on analysis
Browse files Browse the repository at this point in the history
closes #412
  • Loading branch information
lmenezes committed Feb 14, 2020
1 parent 5317ddd commit 9dbece3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 43 deletions.
13 changes: 9 additions & 4 deletions app/models/analysis/IndexFields.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ object IndexFields {

def apply(index: String, data: JsValue) = {
val docTypes = (data \ index \ "mappings").as[JsObject].keys
val fields = docTypes.flatMap { docType =>
extractProperties((data \ index \ "mappings" \ docType \ "properties").as[JsValue])
}.toSeq
JsArray(fields.map(JsString(_)))
val fields = if (docTypes.size == 1 && docTypes.head == "properties") {
extractProperties((data \ index \ "mappings" \ "properties").as[JsValue])
} else { // FIXME: ES < 7
docTypes.flatMap { docType =>
extractProperties((data \ index \ "mappings" \ docType \ "properties").as[JsValue])
}.toSeq
}

JsArray(fields.map(JsString))
}

def extractProperties(data: JsValue): Seq[String] = {
Expand Down
72 changes: 33 additions & 39 deletions test/models/analysis/IndexFieldsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object IndexFieldsSpec extends Specification {
s2"""
IndexField should
should return only string fields $regularFields
should return fields from all types $multipleTypes
should return fields from all types $multipleTypes FIXME < 7
should return sub fields on multi fields fields $multiFields
should return properties of object fields $objects

Expand All @@ -21,18 +21,16 @@ object IndexFieldsSpec extends Specification {
|{
| "index_name": {
| "mappings": {
| "type_1": {
| "properties": {
| "regular_field": {
| "type": "string"
| },
| "regular_field_2": {
| "type": "string",
| "analyzer": "standard"
| },
| "ignored_field": {
| "type": "integer"
| }
| "properties": {
| "regular_field": {
| "type": "string"
| },
| "regular_field_2": {
| "type": "string",
| "analyzer": "standard"
| },
| "ignored_field": {
| "type": "integer"
| }
| }
| }
Expand Down Expand Up @@ -78,17 +76,15 @@ object IndexFieldsSpec extends Specification {
|{
| "index_name": {
| "mappings": {
| "type_1": {
| "properties": {
| "multi_field": {
| "type": "string",
| "fields": {
| "sub_field": {
| "type": "string"
| },
| "ignored_sub_field": {
| "type": "integer"
| }
| "properties": {
| "multi_field": {
| "type": "string",
| "fields": {
| "sub_field": {
| "type": "string"
| },
| "ignored_sub_field": {
| "type": "integer"
| }
| }
| }
Expand All @@ -108,22 +104,20 @@ object IndexFieldsSpec extends Specification {
|{
| "index_name": {
| "mappings": {
| "type_1": {
| "properties": {
| "object_type": {
| "properties": {
| "first_level_property": {
| "properties": {
| "second_level_property": {
| "type": "string"
| }
| "properties": {
| "object_type": {
| "properties": {
| "first_level_property": {
| "properties": {
| "second_level_property": {
| "type": "string"
| }
| },
| "first_level_property_2": {
| "properties": {
| "second_level_property": {
| "type": "string"
| }
| }
| },
| "first_level_property_2": {
| "properties": {
| "second_level_property": {
| "type": "string"
| }
| }
| }
Expand Down

0 comments on commit 9dbece3

Please sign in to comment.