# Indexing of empty arrays affecting search results

**URL:** <https://discuss.elastic.co/t/indexing-of-empty-arrays-affecting-search-results/291006>\
**Category:** Elasticsearch\
**Created:** [December 6, 2021, 4:20am UTC](https://discuss.elastic.co/t/indexing-of-empty-arrays-affecting-search-results/291006 "2021-12-06T04:20:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael-jaxsta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael-jaxsta/32/98320_2.png) [@michael-jaxsta](https://discuss.elastic.co/u/michael-jaxsta)\
**Post date:** [December 6, 2021, 4:20am UTC](https://discuss.elastic.co/t/indexing-of-empty-arrays-affecting-search-results/291006/1 "2021-12-06T04:20:46Z")

</div>

Hi all,

We are using Elasticsearch for searching content on our website which is primarily musician names.

The primary search field is `"name"` but we also have a number of secondary index fields included in the search such as an `"aliases"` field for matching the musician's stage name rather than their real name. Since a musician can have several aliases, this stored as an array e.g. Sean Combs has aliases Puff Daddy and P. Diddy.

Note that `"aliases"` is part of the `"secondary_index_field"` object.

A problem arises if a document is indexed where the "name" fields has a full stop e.g. "Portugal. The Man" and the aliases field is an empty array as per the example below.

```auto
{
  "_index": "jaxsta-20211124-231212",
  "_type": "_doc",
  "_id": "d0140c45-3122-4934-9d83-f4429c048069",
  "_version": 2,
  "_score": 0,
  "_source": {
    "jaxsta_uuid": "d0140c45-3122-4934-9d83-f4429c048069",
    "name": "Portugal. The Man",
    "secondary_index_field": {
      "entity_aliases": [],
      "identifiers": [
        "167649475",
        "4kI8Ie27vjvonwaB2ePh8T"
      ]
    }
  }
}

```

When I use the following search query, the document above **is not** returned.

```auto
GET jaxsta/_search
{
  "size": 2000,
  "query": {
    "function_score": {
      "query": {
        "multi_match": {
          "query": "Portugal. The Man",
          "fields": [
            "name",
            "secondary_index_field.entity_aliases",
            "secondary_index_field.identifiers"
          ],
          "type": "cross_fields"
        }
      }
    }
  }
}

```

But if I remove `"secondary_index_field.entity_aliases"` from the fields list, the correct document is returned in the search result.

In terms of mapping, we are using the following for these fields:

```auto
"name" : {
  "type" : "text",
  "fields" : {
	"keyword" : {
	  "type" : "keyword",
	  "ignore_above" : 256
	}
  }
},
"secondary_index_field" : {
  "properties" : {
	"entity_aliases" : {
	  "type" : "text",
	  "fields" : {
		"keyword" : {
		  "type" : "keyword",
		  "ignore_above" : 256
		}
	  }
	}
  }
}

```

Can anyone suggest what we are doing wrong?

Thanks,

Michael Stone

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 3, 2022, 4:21am UTC](https://discuss.elastic.co/t/indexing-of-empty-arrays-affecting-search-results/291006/2 "2022-01-03T04:21:06Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
