# Match queries where the text input come from another field?

**URL:** <https://discuss.elastic.co/t/match-queries-where-the-text-input-come-from-another-field/141982>\
**Category:** Elasticsearch\
**Created:** [July 27, 2018, 6:13pm UTC](https://discuss.elastic.co/t/match-queries-where-the-text-input-come-from-another-field/141982 "2018-07-27T18:13:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ljak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ljak/32/40307_2.png) [@ljak](https://discuss.elastic.co/u/ljak)\
**Post date:** [July 27, 2018, 6:13pm UTC](https://discuss.elastic.co/t/match-queries-where-the-text-input-come-from-another-field/141982/1 "2018-07-27T18:13:11Z")

</div>

Hi everyone,

I tried to "resolve" that query in the last hours by combining different types of queries (script, synonyms, filter, ...) without success.

Let's say that I index documents according to that mapping :

```auto
PUT /meas/my_type/1
{
  "text": "There is a 1.5 cm gap.",
  "meas": [
        {
          "x": "1.5",
          "token": "1.5 cm",
          "expression": "MX015"
        }
    ]
}

```

The idea is that the nested object contains 'meta'-information on some tokens from the source sentence. With that , we would like to find a token in the source sentence by searching for a value inside the meta-information. Example : I search for "MX015" and ElasticSearch returns and highlights "1.5 cm".

The query could look like this:

```auto
GET meas/_search
{
  "query": {
    "bool": {
      "must": {
          "match": {
            "text": "{{meas.token}}"
          }
      },
      "filter": {
        "nested": {
          "path": "meas",
          "query": {
            "term": {
              "meas.expression": "mx015"
            }
          }
        }
      }
    }
  },
  "highlight" : {
        "fields" : {
            "text" : {}
        },
        "number_of_fragments": 0
    }
}

```

(I use the `moustache` syntax to show that the input text for the match query is a parameter).

Explicitly : the filter on the nested object (which is a document) returns all the "source" documents (with the nested doc) in the index that match the nested query. Next, for each document (from the filter), it can apply the match query where the input text is the value of a field from the nested object from that document.

Any thought ?

Thanks !

---

<div class="post-metadata">

**Author:** ![ljak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ljak/32/40307_2.png) [@ljak](https://discuss.elastic.co/u/ljak)\
**Post date:** [July 31, 2018, 7:38pm UTC](https://discuss.elastic.co/t/match-queries-where-the-text-input-come-from-another-field/141982/2 "2018-07-31T19:38:45Z")

</div>

Any thought ?

Thanks

---

<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:** [August 28, 2018, 7:39pm UTC](https://discuss.elastic.co/t/match-queries-where-the-text-input-come-from-another-field/141982/3 "2018-08-28T19:39:01Z")

</div>

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