# ElasticSearch won't search specific field

**URL:** <https://discuss.elastic.co/t/elasticsearch-wont-search-specific-field/295201>\
**Category:** Elasticsearch\
**Created:** [January 24, 2022, 8:59am UTC](https://discuss.elastic.co/t/elasticsearch-wont-search-specific-field/295201 "2022-01-24T08:59:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bert\_coenen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bert_coenen/32/100772_2.png) [@bert\_coenen](https://discuss.elastic.co/u/bert_coenen)\
**Post date:** [January 24, 2022, 8:59am UTC](https://discuss.elastic.co/t/elasticsearch-wont-search-specific-field/295201/1 "2022-01-24T08:59:30Z")

</div>

I have a problem searching a specific field inside my index.

**little background:**

On my project we need to search inside a terminology Server like FHIR but then our own. So we have an object that contains a Code (123564/A), multiple translations as term/display (urine problem) and mapping to other codes that are equal to that code but in a different system (ICD-10, SNOMED-CT, ICPC-2,..) example what has been indexed:

```auto
{
"Code": "10008220/A1",
"EffectiveTime": "0001-01-01T00:00:00Z",
"Active": true,
"System": "ibui",
"Purpose": "",
"Descriptions": [
    {
        "DescriptionId": "2464cf5c-d4fc-4a61-b6bc-746d003cb4ef",
        "Code": "10008220/A1",
        "System": "ibui",
        "Term": "gebroken arm",
        "LanguageId": "3d50c237-0add-43e7-92a2-5edf1ac7c6ee",
        "FSN": false,
        "Preferred": true,
        "EffectiveTime": "0001-01-01T00:00:00Z",
        "Active": true,
        "SendVersion": "2021-12-07T17:01:53.786755Z",
        "Purpose": ""
    },
    {
        "DescriptionId": "95501583-9f24-4964-bbc9-1a6e95eba30f",
        "Code": "10008220/A1",
        "System": "ibui",
        "Term": "fracture du bras",
        "LanguageId": "1238dde0-08df-4ae0-8676-59919f66737e",
        "FSN": false,
        "Preferred": true,
        "EffectiveTime": "0001-01-01T00:00:00Z",
        "Active": true,
        "SendVersion": "2021-12-07T17:01:53.786755Z",
        "Purpose": ""
    }
],
"Mappings": [
    {
        "MappingId": "",
        "FromSys": "ibui",
        "From": "10008220/A1",
        "ToSys": "icd-10",
        "To": "T10",
        "EffectiveTime": "0001-01-01T00:00:00Z",
        "Active": true
    },
    {
        "MappingId": "",
        "FromSys": "ibui",
        "From": "10008220/A1",
        "ToSys": "icpc-2",
        "To": "L76",
        "EffectiveTime": "0001-01-01T00:00:00Z",
        "Active": true
    }
],
"SendVersion": "2021-12-07T17:01:53.786755Z"
}

```

**The problem:** We can search on 2 different fields : Code & Term. and when searching we keep in mind that we have some filters for a specific language code (Dutch,..) or A system like ICD-10 or ICPC-2,..

I have a query that is working and returns the above object when searching in 1 field (Descriptions.Term) that is the following:

**working query**

```auto
{
  "query": {
    "bool": {
      "must": {
        "nested": {
          "inner_hits": {
            "highlight": {
              "fields": {
                "*": {}
              }
            }
          },
          "path": "Descriptions",
          "query": {
            "bool": {
              "should": [
                {
                  "multi_match": {
                    "fields": [
                      "Descriptions.Term",
                      "Descriptions.Term._2gram",
                      "Descriptions.Term._3gram"
                    ],
                    "query": "gebroken*~ n",
                    "type": "bool_prefix"
                  }
                }
              ],
              "filter": [
                {
                            "bool": {
                                "should": [
                                    {
                            "term": {
                                    "Descriptions.System": "ibui"
                                    }
                            },{
                            "term": {
                                    "Descriptions.System": "icd-10"
                                    }
                            },{
                            "term": {
                                    "Descriptions.System": "icpc-2"
                                    }
                            }
                                ],
                                "minimum_should_match": "1"
                                }
                            },
                
                {
                            "term": {
                                    "Descriptions.Active": "true"
                                    }
                            },
                {
                  "term": {
                    "Descriptions.LanguageId": "3d50c237-0add-43e7-92a2-5edf1ac7c6ee"
                  }
                }
              ]
            }
          }
        }
      }
      
    }
  }
}

```

But when we somethings need to search in multiple fields. When adding the Descriptions.Code field to the fields map the query is not working and I can't figure out why. I have it decleared inside my mapping so it should be searchable? I'm searching for the Code of the object above in both fields (Descriptions.Term & Descriptions.Code) but it doesn't returns the hit.

**not working query**

```auto
  {
  "query": {
    "bool": {
      "must": {
        "nested": {
          "inner_hits": {
            "highlight": {
              "fields": {
                "*": {}
              }
            }
          },
          "path": "Descriptions",
          "query": {
            "bool": {
              "should": [
                {
                  "multi_match": {
                    "fields": [
                      "Descriptions.Term",
                      "Descriptions.Term._2gram",
                      "Descriptions.Term._3gram",
                      "Descriptions.Code"
                    ],
                    "query": "10008220*~ n",
                    "type": "bool_prefix"
                  }
                }
              ],
              "filter": [
                {
                            "bool": {
                                "should": [
                                    {
                            "term": {
                                    "Descriptions.System": "ibui"
                                    }
                            },{
                            "term": {
                                    "Descriptions.System": "icd-10"
                                    }
                            },{
                            "term": {
                                    "Descriptions.System": "icpc-2"
                                    }
                            }
                                ],
                                "minimum_should_match": "1"
                                }
                            },
                
                {
                            "term": {
                                    "Descriptions.Active": "true"
                                    }
                            },
                {
                  "term": {
                    "Descriptions.LanguageId": "3d50c237-0add-43e7-92a2-5edf1ac7c6ee"
                  }
                }
              ]
            }
          }
        }
      }
      
    }
  }
}

```

**mapping:**

```auto
  {
    "settings": {
        "number_of_shards": 1,
        "analysis": {
            "analyzer": {
                "autocomplete": {
                    "tokenizer": "custom_tokenizer"
                }
            },
            "tokenizer": {
                "custom_tokenizer": {
                    "type": "ngram",
                    "min_gram": 2,
                    "max_gram": 6,
                    "token_chars": [
                        "letter",
                        "digit",
                        "symbol",
                        "punctuation"
                    ]
                }
            }
        },
        "max_ngram_diff" : "5"
    },
  "mappings": {
    "properties": {
      "Descriptions": {
        "type": "nested",
        "properties": {
          "Term": {
            "type": "search_as_you_type",
            "analyzer": "autocomplete"
          },
          "Code": {
            "type": "keyword",
            "index": true
          },
          "System": {
            "type": "keyword",
            "index": true
          },
          "LanguageId": {
            "type": "keyword",
            "index": true
          },
          "Purpose": {
            "type": "keyword",
            "index": true
          },
          "Active": {
            "type": "keyword",
            "index": true
          }
        }
      },
      "Mappings": {
        "properties": {
          "To": {
            "type": "keyword",
            "index": true
          },
          "ToSys": {
            "type": "keyword",
            "index": true
          }
        }
      }
    }
  }
}

```

I really don't see the mistake I made. also If anyone has other suggestions to improve the search query, feel free

Thank you

---

<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:** [February 21, 2022, 8:59am UTC](https://discuss.elastic.co/t/elasticsearch-wont-search-specific-field/295201/2 "2022-02-21T08:59:35Z")

</div>

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