Z
Z
zencd2021-02-27 21:37:17
elasticsearch
zencd, 2021-02-27 21:37:17

How to find out which array element is matched in Elastic Search?

Among documents successfully I do search in an array "names".

Question: how to understand which of the elements is matched inside the score-function? Index or string value.

Document:

{
  "names": [
    { "name_norm": "redone" },
    { "name_norm": "purpleone" }
  ]
}

Search:

POST /named_index/named/_search?pretty=true&explain=true
{
  "query": {
    "function_score": {
      "query": {
        "regexp": {
          "names.name_norm": {"value": "purpleone"}
        }
      },
      "script_score": {
        "script": {
          "source": "100.0"
        }}}}}

Complete: https://gist.github.com/zencd/f17943c2af89b9b6de02...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zencd, 2021-02-28
@zencd

Matched string:
{"source": "doc['names.name_norm'].value"}
Its length:

{"source": "doc['names.name_norm'].value.length()"}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question