1

I need a help about getting an array item with indice ([0] e.g.) in elasticsearch. Whatever painless or scriptless behaviour.

Here is my little test mapping, document and results;

"mappings": {
    "tip": {
        "properties": {
            "name": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "props": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            }
        }
    }
}

And I indexed one document like that;

{
    "name": "burak",
    "props": [
        "4",
        "2",
        "3"
    ]
}

When I get "props" values with painless script the values of props fetched as ordered. I don't want this, how can I fix it ?

{
  "script_fields": {
    "FIELD": {
      "script": {
        "inline": "doc['props.keyword']",
        "lang": "painless"

      }
    }
  }
}

The result was;

"fields": {
          "FIELD": [
            "2",
            "3",
            "4"
          ]
        }
btungut
  • 23
  • 3
  • Why do you need a script field for that? why not simply retrieving `props` from the source? – Val Jul 27 '17 at 09:06
  • @Val as I said begining of the topic, I need to access an array item with indice, like that props[150], that's why I try scripting. – btungut Jul 27 '17 at 11:12
  • Ok, but if you access a single element, you don't need to worry about the ordering, since you'll only get one element, right? – Val Jul 27 '17 at 11:22
  • @Val actually orderding is important for me, I need the original values (how I indexed exactly). Cuz, at the index time the first item ([0]) was "4", then I when I want to fetch first item [0] with script it suddenly would be "2". – btungut Jul 27 '17 at 11:44

0 Answers0