{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/34356","repository_url":"https://api.github.com/repos/elastic/elasticsearch","labels_url":"https://api.github.com/repos/elastic/elasticsearch/issues/34356/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/34356/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/34356/events","html_url":"https://github.com/elastic/elasticsearch/issues/34356","id":367751255,"node_id":"MDU6SXNzdWUzNjc3NTEyNTU=","number":34356,"title":"Unexpected Behavior in output after firing Script to search across multiple Indices","user":{"login":"TejasC-CS","id":42927224,"node_id":"MDQ6VXNlcjQyOTI3MjI0","avatar_url":"https://avatars1.githubusercontent.com/u/42927224?v=4","gravatar_id":"","url":"https://api.github.com/users/TejasC-CS","html_url":"https://github.com/TejasC-CS","followers_url":"https://api.github.com/users/TejasC-CS/followers","following_url":"https://api.github.com/users/TejasC-CS/following{/other_user}","gists_url":"https://api.github.com/users/TejasC-CS/gists{/gist_id}","starred_url":"https://api.github.com/users/TejasC-CS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TejasC-CS/subscriptions","organizations_url":"https://api.github.com/users/TejasC-CS/orgs","repos_url":"https://api.github.com/users/TejasC-CS/repos","events_url":"https://api.github.com/users/TejasC-CS/events{/privacy}","received_events_url":"https://api.github.com/users/TejasC-CS/received_events","type":"User","site_admin":false},"labels":[{"id":141141324,"node_id":"MDU6TGFiZWwxNDExNDEzMjQ=","url":"https://api.github.com/repos/elastic/elasticsearch/labels/:Search/Aggregations","name":":Search/Aggregations","color":"0e8a16","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-10-08T11:43:16Z","updated_at":"2018-10-14T18:42:12Z","closed_at":"2018-10-14T18:42:12Z","author_association":"NONE","body":"**Elasticsearch version** (`bin/elasticsearch --version`): \"6.4.2\"\r\n\r\n**Plugins installed**: No Plugins Installed\r\n\r\n**JVM version** (`java -version`): \"1.8.0_181\"\r\n\r\n**OS version** (`uname -a` if on a Unix-like system): \"Windows 10 Pro\"\r\n\r\n**Description of the problem including expected versus actual behavior**: Unexpected behavior on firing rest call to search across multiple indexes using script in query.\r\n\r\n**Steps to reproduce**:\r\n\r\nIn my case there are two indexes named model_cluster_02 and model_edge_01.\r\nMapping in these indexes is as follows:\r\n\r\n\"model_edge_01\": {\r\n        \"mappings\": {\r\n            \"em\": {\r\n                \"properties\": {\r\n                    \"distance\": {\r\n                        \"type\": \"long\"\r\n                    },\r\n                    \"edge_id\": {\r\n                        \"type\": \"text\",\r\n                        \"fields\": {\r\n                            \"keyword\": {\r\n                                \"type\": \"keyword\",\r\n                                \"ignore_above\": 256\r\n                            }\r\n                        },\r\n                        \"fielddata\": true\r\n                    },\r\n                    \"from\": {\r\n                        \"type\": \"text\",\r\n                        \"fields\": {\r\n                            \"keyword\": {\r\n                                \"type\": \"keyword\",\r\n                                \"ignore_above\": 256\r\n                            }\r\n                        },\r\n                        \"fielddata\": true\r\n                    },\r\n                    \"to\": {\r\n                        \"type\": \"text\",\r\n                        \"fields\": {\r\n                            \"keyword\": {\r\n                                \"type\": \"keyword\",\r\n                                \"ignore_above\": 256\r\n                            }\r\n                        },\r\n                        \"fielddata\": true\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    },\r\n    \"model_cluster_02\": {\r\n        \"mappings\": {\r\n            \"cm_001\": {\r\n                \"properties\": {\r\n                    \"cluster_id\": {\r\n                        \"type\": \"text\",\r\n                        \"fields\": {\r\n                            \"keyword\": {\r\n                                \"type\": \"keyword\",\r\n                                \"ignore_above\": 256\r\n                            }\r\n                        },\r\n                        \"fielddata\": true\r\n                    },\r\n                    \"edges\": {\r\n                        \"type\": \"text\",\r\n                        \"fields\": {\r\n                            \"keyword\": {\r\n                                \"type\": \"keyword\",\r\n                                \"ignore_above\": 256\r\n                            }\r\n                        },\r\n                        \"fielddata\": true\r\n                    },\r\n                    \"tags\": {\r\n                        \"properties\": {\r\n                            \"Accessories\": {\r\n                                \"type\": \"long\"\r\n                            },\r\n                            \"Clothing\": {\r\n                                \"type\": \"long\"\r\n                            },\r\n                            \"Female\": {\r\n                                \"type\": \"long\"\r\n                            },\r\n                            \"Football\": {\r\n                                \"type\": \"long\"\r\n                            },\r\n                            \"Footware\": {\r\n                                \"type\": \"long\"\r\n                            },\r\n                            \"Formal\": {\r\n                                \"type\": \"long\"\r\n                            },\r\n                            \"Hockey\": {\r\n                                \"type\": \"long\"\r\n                            },\r\n                            \"Male\": {\r\n                                \"type\": \"long\"\r\n                            },\r\n                            \"Sports\": {\r\n                                \"type\": \"long\"\r\n                            },\r\n                            \"Tennis\": {\r\n                                \"type\": \"long\"\r\n                            }\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    } \r\n\r\nAs you can see \"fielddata\" is set to true to use values of those particular fields in script.\r\nTo search across multiple indexes, we fire rest call to elasticsearch like:\r\nGET/model_edge_01,model_cluster_02/_search\r\n\r\nAfter firing this rest call we'll get results from both the indexes.\r\nBut when we write a script in query and fire it, search results are as expected in case of fields of 1st index in the URL (i.e. model_edge_01).\r\nBut we get unexpected search results in case of 2nd index(i.e. model_cluster_02).\r\nQuery, results for the fired query and expected results are as follows:\r\n{\r\n    \"query\": {\r\n    \t\"bool\":{\r\n    \t\t \t\"must\":[\r\n        \t\t   {\r\n\t\t\t\t\t\t\"match\":{\r\n\t\t\t\t\t\t\t\"to\":\"p12\"\r\n\t\t\t\t\t\t}\r\n        \t\t   },\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t\"script\" :{\r\n\t\t\t\t\t\t \t\"script\":\"doc['edge_id'].value == doc['to'].value\"\r\n\t\t\t\t\t\t}\t\r\n                \t}\r\n    \t\t \t]\r\n    \t}\r\n    }\r\n}\r\n\r\nExpected Result:\r\n{\r\n    \"took\": 9,\r\n    \"timed_out\": false,\r\n    \"_shards\": {\r\n        \"total\": 10,\r\n        \"successful\": 10,\r\n        \"skipped\": 0,\r\n        \"failed\": 0\r\n    },\r\n    \"hits\": {\r\n        \"total\": 0,\r\n        \"max_score\": null,\r\n        \"hits\": []\r\n    }\r\n}\r\nAnd we are getting the same result as model_edge_01 is the first index in url.\r\n\r\n\r\nBut in case where we'll use fields of second index in script, we get unexpected result as follows:\r\n\r\n{\r\n    \"query\": {\r\n    \t\"bool\":{\r\n    \t\t \t\"must\":[\r\n        \t\t   {\r\n\t\t\t\t\t\t\"match\":{\r\n\t\t\t\t\t\t\t\"to\":\"p12\"\r\n\t\t\t\t\t\t}\r\n        \t\t   },\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t\"script\" :{\r\n\t\t\t\t\t\t \t\"script\":\"doc['tags'].value == doc['cluster_id'].value\"\r\n\t\t\t\t\t\t}\t\r\n                \t}\r\n    \t\t \t]\r\n    \t}\r\n    }\r\n}\r\n\r\nExpected result:\r\n{\r\n    \"took\": 9,\r\n    \"timed_out\": false,\r\n    \"_shards\": {\r\n        \"total\": 10,\r\n        \"successful\": 10,\r\n        \"skipped\": 0,\r\n        \"failed\": 0\r\n    },\r\n    \"hits\": {\r\n        \"total\": 0,\r\n        \"max_score\": null,\r\n        \"hits\": []\r\n    }\r\n}\r\n\r\nResult we are getting:\r\n{\r\n    \"took\": 14,\r\n    \"timed_out\": false,\r\n    \"_shards\": {\r\n        \"total\": 10,\r\n        \"successful\": 9,\r\n        \"skipped\": 0,\r\n        \"failed\": 1,\r\n        \"failures\": [\r\n            {\r\n                \"shard\": 1,\r\n                \"index\": \"model_edge_01\",\r\n                \"node\": \"J3GgjhjLTbOiRyn2RJJZAQ\",\r\n                \"reason\": {\r\n                    \"type\": \"script_exception\",\r\n                    \"reason\": \"runtime error\",\r\n                    \"script_stack\": [\r\n                        \"org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:81)\",\r\n                        \"org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:39)\",\r\n                        \"doc['tags'].value == doc['cluster_id'].value\",\r\n                        \"    ^---- HERE\"\r\n                    ],\r\n                    \"script\": \"doc['tags'].value == doc['cluster_id'].value\",\r\n                    \"lang\": \"painless\",\r\n                    \"caused_by\": {\r\n                        \"type\": \"illegal_argument_exception\",\r\n                        \"reason\": \"No field found for [tags] in mapping with types []\"\r\n                    }\r\n                }\r\n            }\r\n        ]\r\n    },\r\n    \"hits\": {\r\n        \"total\": 0,\r\n        \"max_score\": null,\r\n        \"hits\": []\r\n    }\r\n}\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments/429651101","html_url":"https://github.com/elastic/elasticsearch/issues/34356#issuecomment-429651101","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/34356","id":429651101,"node_id":"MDEyOklzc3VlQ29tbWVudDQyOTY1MTEwMQ==","user":{"login":"rjernst","id":289412,"node_id":"MDQ6VXNlcjI4OTQxMg==","avatar_url":"https://avatars3.githubusercontent.com/u/289412?v=4","gravatar_id":"","url":"https://api.github.com/users/rjernst","html_url":"https://github.com/rjernst","followers_url":"https://api.github.com/users/rjernst/followers","following_url":"https://api.github.com/users/rjernst/following{/other_user}","gists_url":"https://api.github.com/users/rjernst/gists{/gist_id}","starred_url":"https://api.github.com/users/rjernst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjernst/subscriptions","organizations_url":"https://api.github.com/users/rjernst/orgs","repos_url":"https://api.github.com/users/rjernst/repos","events_url":"https://api.github.com/users/rjernst/events{/privacy}","received_events_url":"https://api.github.com/users/rjernst/received_events","type":"User","site_admin":false},"created_at":"2018-10-14T18:42:12Z","updated_at":"2018-10-14T18:42:12Z","author_association":"MEMBER","body":"Thanks very much for your interest in Elasticsearch.\r\n\r\nThis appears to be a user question, and we'd like to direct these kinds of things to the [forums](https://discuss.elastic.co). If you can stop by there, we'd appreciate it. This allows us to use GitHub for verified bug reports, feature requests, and pull requests.\r\n\r\nAs a starter to finding a solution to your problem, note that the `tags` field does not exist in your first index. There's an active community in the [forums](https://discuss.elastic.co) that should be able to help get an answer to your question. As such, I hope you don't mind that I close this."}}
{"actor":{"display_login":"rjernst"}}