Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CCS: terms lookup query doesn't support looking up terms on remote indices #61364

Closed
lucabelluccini opened this issue Aug 20, 2020 · 5 comments · Fixed by #76371
Closed

CCS: terms lookup query doesn't support looking up terms on remote indices #61364

lucabelluccini opened this issue Aug 20, 2020 · 5 comments · Fixed by #76371
Assignees
Labels
>docs General docs changes :Search/Search Search-related issues that do not fall into other categories

Comments

@lucabelluccini
Copy link
Contributor

Elasticsearch version (bin/elasticsearch --version): 7.6.2, 7.9.0

JVM version (java -version): bundled

Description of the problem including expected versus actual behavior:

It is not possible to use the terms lookup query using a remote index. A 404 error is returned.

Steps to reproduce:

  1. Setup a cluster called main
  2. Setup a cluster called ccs
  3. Configure the ccs cluster to connect to the main cluster using the steps provided in our documentation
  4. Create the following data on the main cluster (as per example) and test the lookup terms search:
PUT my-index-000001
{
  "mappings": {
    "properties": {
      "color": { "type": "keyword" }
    }
  }
}

PUT my-index-000001/_doc/1
{
  "color":   ["blue", "green"]
}

PUT my-index-000001/_doc/2
{
  "color":   "blue"
}

GET my-index-000001/_search?pretty
{
  "query": {
    "terms": {
        "color" : {
            "index" : "my-index-000001",
            "id" : "2",
            "path" : "color"
        }
    }
  }
}
# Response
{
  "took" : 17,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "my-index-000001",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "color" : [
            "blue",
            "green"
          ]
        }
      },
      {
        "_index" : "my-index-000001",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "color" : "blue"
        }
      }
    ]
  }
}
  1. Use the elastic (superuser) to avoid any security role to setup
  2. Search from the ccs cluster to the main cluster (works ok) with a match all query
GET main:my-index-000001/_search
# Response
{
  "took": 4,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "_clusters": {
    "total": 1,
    "successful": 1,
    "skipped": 0
  },
  "hits": {
    "total": {
      "value": 2,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "main:my-index-000001",
        "_type": "_doc",
        "_id": "1",
        "_score": 1,
        "_source": {
          "color": [
            "blue",
            "green"
          ]
        }
      },
      {
        "_index": "main:my-index-000001",
        "_type": "_doc",
        "_id": "2",
        "_score": 1,
        "_source": {
          "color": "blue"
        }
      }
    ]
  }
}
  1. Use a Terms lookup query on a remote index both with and without prefixing it with main (it fails)
POST main:my-index-000001/_search
{
  "query": {
    "terms": {
        "color" : {
            "index" : "main:my-index-000001",
            "path": "color",
            "id": "2"
        }
    }
  }
}
# Response
{
  "error": {
    "root_cause": [
      {
        "type": "index_not_found_exception",
        "reason": "no such index [main:my-index-000001]",
        "resource.type": "index_expression",
        "resource.id": "main:my-index-000001",
        "index_uuid": "_na_",
        "index": "main:my-index-000001"
      }
    ],
    "type": "index_not_found_exception",
    "reason": "no such index [main:my-index-000001]",
    "resource.type": "index_expression",
    "resource.id": "main:my-index-000001",
    "index_uuid": "_na_",
    "index": "main:my-index-000001"
  },
  "status": 404
}

POST main:my-index-000001/_search
{
  "query": {
    "terms": {
        "color" : {
            "index" : "my-index-000001",
            "path": "color",
            "id": "2"
        }
    }
  }
}
# Response
{
  "error": {
    "root_cause": [
      {
        "type": "index_not_found_exception",
        "reason": "no such index [my-index-000001]",
        "resource.type": "index_expression",
        "resource.id": "my-index-000001",
        "index_uuid": "_na_",
        "index": "my-index-000001"
      }
    ],
    "type": "index_not_found_exception",
    "reason": "no such index [my-index-000001]",
    "resource.type": "index_expression",
    "resource.id": "my-index-000001",
    "index_uuid": "_na_",
    "index": "my-index-000001"
  },
  "status": 404
}
@lucabelluccini lucabelluccini added >bug needs:triage Requires assignment of a team area label labels Aug 20, 2020
@javanna javanna added the :Search/Search Search-related issues that do not fall into other categories label Aug 20, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Search)

@elasticmachine elasticmachine added the Team:Search Meta label for search team label Aug 20, 2020
@javanna javanna removed Team:Search Meta label for search team needs:triage Requires assignment of a team area label labels Aug 20, 2020
@javanna
Copy link
Member

javanna commented Aug 20, 2020

This requires knowledge about how the terms query works internally. Terms lookup uses the get API to retrieve the document that contains the ids. Get is not search, hence it has no cross-cluster support, meaning index prefixes don't get resolved, and indices can only be local. The terms query gets rewritten on the coordinating node (CCS cluster when using CCS), and as part of the rewrite phase the document containing the ids is fetched locally.

This can only work if the lookup data is located in the CCS cluster, and no index prefix is used in the terms query definition.

Otherwise, the lookup can also happen on the client side. Terms lookup is concise, but it isn't more optimized than fetching the ids and providing them directly as part of the terms query, that is what happens under the hood anyways.

@javanna
Copy link
Member

javanna commented Aug 31, 2020

I wonder if this should be considered a bug, or maybe converted into a doc improvement to document the limitation that I described above.

@javanna
Copy link
Member

javanna commented Sep 17, 2020

@lucabelluccini can I get feedback on the explanation I gave above?

@javanna javanna added >docs General docs changes and removed >bug labels Sep 18, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-docs (>docs)

@elasticmachine elasticmachine added the Team:Docs Meta label for docs team label Sep 18, 2020
@javanna javanna added help wanted adoptme and removed Team:Docs Meta label for docs team labels Sep 18, 2020
@javanna javanna changed the title Terms lookup query doesn't support looking up terms on remote indices CCS: terms lookup query doesn't support looking up terms on remote indices Sep 18, 2020
@jrodewig jrodewig removed the help wanted adoptme label Aug 11, 2021
@jrodewig jrodewig self-assigned this Aug 11, 2021
jrodewig added a commit that referenced this issue Aug 12, 2021
Changes:
* Notes that you can't use cross-cluster search to run a terms lookup on a remote index.
* Removes a redundant sentence noting `_source` is enabled by default.

Closes #61364.
elasticsearchmachine pushed a commit that referenced this issue Aug 12, 2021
Changes:
* Notes that you can't use cross-cluster search to run a terms lookup on a remote index.
* Removes a redundant sentence noting `_source` is enabled by default.

Closes #61364.
elasticsearchmachine pushed a commit that referenced this issue Aug 12, 2021
Changes:
* Notes that you can't use cross-cluster search to run a terms lookup on a remote index.
* Removes a redundant sentence noting `_source` is enabled by default.

Closes #61364.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>docs General docs changes :Search/Search Search-related issues that do not fall into other categories
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants