Match queries where the text input come from another field?

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 :

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:

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 !

Any thought ?

Thanks

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