# Elasticsearch | Max\_Expansions and copy\_to field in Multi\_Match query

**URL:** <https://discuss.elastic.co/t/elasticsearch-max-expansions-and-copy-to-field-in-multi-match-query/174496>\
**Category:** Elasticsearch\
**Created:** [March 29, 2019, 8:50am UTC](https://discuss.elastic.co/t/elasticsearch-max-expansions-and-copy-to-field-in-multi-match-query/174496 "2019-03-29T08:50:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)\
**Post date:** [March 29, 2019, 8:50am UTC](https://discuss.elastic.co/t/elasticsearch-max-expansions-and-copy-to-field-in-multi-match-query/174496/1 "2019-03-29T08:50:15Z")

</div>

Hi,  
I am finding few issues with max\_expansions. Moreover there is limited information over this.  
I have created two indices. Both of them contains a Copy\_to field. The name given to both of it is same. I have over 100 fields in index "index\_one" and 50 fields in Index "index\_two"  
My mapping is similar in both indexes (although few fields are different among these indices) :

```
  { "settings": {
           "number_of_shards": "2",
              "analysis": {"filter": { "indexFilter": { "type": "pattern_capture","preserve_original": "true",
                            "patterns": ["([@,$,%,&,!,.,#,^,*]+)", "([\\w,.]+)","([\\w,@]+)", "([-]+)", "(\\w+)"] } },
                    "analyzer": {
                        "indexAnalyzer": {
                            "filter": ["indexFilter", "lowercase"],
                            "tokenizer": "whitespace" },
                        "searchAnalyzer": { "filter": ["lowercase"], "tokenizer": "whitespace" } } } } },
  	  "mappings": { "_doc": {"properties": {
  			"ID": { "type": "text","term_vector": "with_positions_offsets",
                        "fields": {"keyword": {
                                "type": "keyword",
                                "ignore_above": 256 } },
                        "analyzer": "indexAnalyzer",
                        "search_analyzer": "searchAnalyzer"
                    },
                    "FILE_NAME": {
                        "type": "text",
                        "term_vector": "with_positions_offsets",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256 } },
                        "copy_to": ["MONOLITHIC_FIELD"],
                        "analyzer": "indexAnalyzer",
                        "search_analyzer": "searchAnalyzer"
                    },
			"TEXT_ID": {
                        "type": "text",
                        "term_vector": "with_positions_offsets",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256 } },
                        "copy_to": ["MONOLITHIC_FIELD"],
                        "analyzer": "indexAnalyzer",
                        "search_analyzer": "searchAnalyzer"
                    },
                    "SCAN_COPY": { "type": "text",
                        "term_vector": "with_positions_offsets",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256 } },
                        "copy_to": ["MONOLITHIC_FIELD"],
                        "analyzer": "indexAnalyzer",
                        "search_analyzer": "searchAnalyzer" } }} }}

```

Documents indexed is :  
POST : [http://11.43.1.130:9993/index\_one/\_doc/DATA13185](http://11.43.1.130:9993/index_one/_doc/DATA13185)

```
{
"SCAN_COPY": "DATA13185.pdf",
 "TEXT_ID": "DATA13185",
"FILE_NAME": "DATA13185.pdf",
"ID": "439132553aab42f484fa515b2e52d899" }

```

POST : [http://11.43.1.130:9993/index\_two/\_doc/DATA13185\_c2a40abf-916a-4529-9d07-3ed1796c2c19](http://11.43.1.130:9993/index_two/_doc/DATA13185_c2a40abf-916a-4529-9d07-3ed1796c2c19)

```
{ "TEXT_ID": "DATA13185",
        "ID": "439132553aab42f484fa515b2e52d899" }

```

I have a query running on both of these indices at once.  
The query is :

```
{"from" : 0, "query": {
    "bool": {"should": [ {
    "bool": {"should": [{
        "multi_match": {
           "query":"data13185",
           "boost": "10",        
           "operator":"and",                    
           "analyzer":"whitespace",
                  "fuzziness": "AUTO:4,7",
                  "prefix_length":1,
                  "max_expansions":50,
                 "fields":["MONOLITHIC_FIELD"] }}],"minimum_should_match":1}}],"minimum_should_match":1,"filter": [{ "terms": { "ID.keyword" : ["439132553aab42f484fa515b2e52d899"]} } ]}},"highlight": {
        "type" : "unified",
           "fields": { "*": { "require_field_match" : "false" } } }}

```

The highlight results are :

```
 "hits": {
        "total": 1,
        "max_score": 40.16386,
        "hits": [
            {
                "_index": "index_two",
                "_type": "_doc",
                "_id": "DATA13185_c2a40abf-916a-4529-9d07-3ed1796c2c19",
"highlight": {
                    "TEXT_ID": [
                        "<em>DATA13185</em>"
                    ],
                    "ID": [
                        "<em>439132553aab42f484fa515b2e52d899</em>"
                    ],
                    "ID.keyword": ["<em>439132553aab42f484fa515b2e52d899</em>"]
                } } ] }

```

Search matches only in one of the index i.e., "index\_two" even though max\_expansions in set to 50. I know max\_expansions work on a shard level but this should not cause the issue.  
But once when I change the max\_expansions value to 150, both the documents in two different indices are matched.

```
{"from" : 0, "size" : 10, "query": {
    "bool": {"should": [ {
    "bool": {"should": [{
        	
          "multi_match": {
           "query":"data13185",
           "boost": "10",        
           "operator":"and",                    
           "analyzer":"whitespace",
                  "fuzziness": "AUTO:4,7",
                  "prefix_length":1,
                  "max_expansions":150,
                  
    			     "fields":["MONOLITHIC_FIELD"]
}}],"minimum_should_match":1}}],"minimum_should_match":1,"filter": [{ "terms": { "ID.keyword" : ["439132553aab42f484fa515b2e52d899"]} } ]}},"highlight": {
        "type" : "unified",
          
        "fields": {
            "*": { "require_field_match" : "false"
            } } }}

```

The search results are :

```
     "hits": {
            "total": 2,
            "max_score": 90.1923,
            "hits": [
                {
                "_index": "index_one",
                "_type": "_doc",
                "_id": "DATA13185",
                "_score": 90.1923,
    "highlight": {
                        "SCAN_COPY": ["<em>DATA13185.pdf</em>"],
                    "TEXT_ID": ["<em>DATA13185</em>"],
                    "ID": ["<em>439132553aab42f484fa515b2e52d899</em>"],
                    "FILE_NAME": [ "<em>DATA13185.pdf</em>",
                    "ID.keyword": ["<em>439132553aab42f484fa515b2e52d899</em>"]} },
 { **The second hit is same as the one mentioned in previous search result. Due to restriction of characters I have not added it** ]}
```

---

<div class="post-metadata">

**Author:** ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)\
**Post date:** [April 1, 2019, 5:58am UTC](https://discuss.elastic.co/t/elasticsearch-max-expansions-and-copy-to-field-in-multi-match-query/174496/2 "2019-04-01T05:58:06Z")

</div>

@elastic Please provide any information

---

<div class="post-metadata">

**Author:** ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)\
**Post date:** [April 3, 2019, 6:08am UTC](https://discuss.elastic.co/t/elasticsearch-max-expansions-and-copy-to-field-in-multi-match-query/174496/3 "2019-04-03T06:08:46Z")

</div>

@elastic Please provide suggestions if any

---

<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:** [May 1, 2019, 6:08am UTC](https://discuss.elastic.co/t/elasticsearch-max-expansions-and-copy-to-field-in-multi-match-query/174496/4 "2019-05-01T06:08:48Z")

</div>

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