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

More Like This Queries should error when Routing Set to "required" and no routing is supplied #29678

Closed
kylelyk opened this issue Apr 24, 2018 · 9 comments
Labels
>bug good first issue low hanging fruit help wanted adoptme :Search/Search Search-related issues that do not fall into other categories

Comments

@kylelyk
Copy link

kylelyk commented Apr 24, 2018

Elasticsearch version: 6.2.4

Plugins installed: []

JVM version: 1.8.0_101

OS version: MacOS (Darwin Kernel Version 15.6.0)

Description of the problem including expected versus actual behavior:
"More Like This" queries do not return any results when "mappings.type._routing" = true.

Steps to reproduce:

PUT test
{
  "mappings": {
    "type": {
      "_routing": {
        "required": true
      },
      "properties": {
        "myField": {
          "type": "text"
        }
      }
    }
  }
}
POST /_bulk
{ "index":  { "_index": "test", "_type": "type","_id":1, "_routing":1 }}
{"myField":"and_foo"}
{ "index":  { "_index": "test", "_type": "type","_id":2, "_routing":2 }}
{"myField":"and_foo" }

The following query returns no results:

GET /_search
{
  "query": {
    "more_like_this": {
      "fields": [
        "myField"
      ],
      "like": [
        {
          "_index": "test",
          "_type": "type",
          "_id": "1"
        }
      ],
      "min_term_freq": 1,
      "min_doc_freq": 1
    }
  }
}

If the _routing setting in the index mapping is removed, it correctly returns 1 result.

@kylelyk kylelyk changed the title More Like This Queries Return 0 Results when Routing set to "required" More Like This Queries Return 0 Results when Routing Set to "required" Apr 24, 2018
@jbaiera jbaiera added the :Search/Search Search-related issues that do not fall into other categories label Apr 24, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

@colings86 colings86 added >bug and removed >bug labels Apr 25, 2018
@colings86
Copy link
Contributor

You should be able to add a routing field next to the _id field in the like array to specify the routing to use to retrieve the item.

@kylelyk
Copy link
Author

kylelyk commented Apr 25, 2018

Adding the routing field makes the query work as expected. Could an error be returned if you attempt to specify a document without a routing id if routing is set to required? Every other API I have used has given an appropriate error if I forget to set the routing id.

@colings86
Copy link
Contributor

Thats a good suggestion @kylelyk, I'm going to reword the title of this issue to reflect the intention to change to that behaviour and mark it as an adoptme

@colings86 colings86 changed the title More Like This Queries Return 0 Results when Routing Set to "required" More Like This Queries should error when Routing Set to "required" and no routing is supplied Apr 25, 2018
@colings86 colings86 added >bug good first issue low hanging fruit help wanted adoptme labels Apr 25, 2018
@ashishguptak
Copy link

Hello, Can I take up this issue?
any pointers are much appreciated.

@cbismuth
Copy link
Contributor

I'll have a look on this one.

@cbismuth
Copy link
Contributor

cbismuth commented Sep 17, 2018

I can reproduce this issue on master, see Gist here. As @kylelyk said, its returns no result.

{"took":5,"timed_out":false,"_shards":{"total":2,"successful":2,"skipped":0,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}

Besides, Bulk API doesn't seem to allow _routing attribute any more, see error below. I've switched to two POST commands with refresh forced.

{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Action/metadata line [2] contains an unknown parameter [_routing]"}],"type":"illegal_argument_exception","reason":"Action/metadata line [2] contains an unknown parameter [_routing]"},"status":400}

I'm now digging a little deeper in issue resolution and let you know.

EDIT

I've updated Gist test script to trigger a missing routing exception.
RoutingMissingException when searching a document by id with missing routing attribute is thrown from the server action layer, see here.

Unlike the GET API, a MoreLikeThisQuery query has to be parsed into search context to check whether or not the routing attribute field has been set (see here).

@cbismuth
Copy link
Contributor

cbismuth commented Sep 18, 2018

I've opened a pull request to fix this issue, see #33974.

@cbismuth
Copy link
Contributor

cbismuth commented Sep 23, 2018

Obsolete PR closed (due to bad Git rebase operation) and new one opened in sync with master branch.

javanna pushed a commit that referenced this issue Nov 27, 2018
More like this query allows to provide identifiers of documents to be retrieved as like/unlike items.
It can happen that at retrieval time an error is thrown, for instance caused by missing routing value when `_routing` is set required in the mapping.
Instead of ignoring such error and returning no documents for the query, the error should be re-thrown and returned to users. As part of this
change also mget and mtermvectors are unified in the way they throw such exception like it happens in other places, so that a `RoutingMissingException` is raised.

Closes #29678
javanna pushed a commit that referenced this issue Nov 27, 2018
More like this query allows to provide identifiers of documents to be retrieved as like/unlike items.
It can happen that at retrieval time an error is thrown, for instance caused by missing routing value when `_routing` is set required in the mapping.
Instead of ignoring such error and returning no documents for the query, the error should be re-thrown and returned to users. As part of this
change also mget and mtermvectors are unified in the way they throw such exception like it happens in other places, so that a `RoutingMissingException` is raised.

Closes #29678
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug good first issue low hanging fruit help wanted adoptme :Search/Search Search-related issues that do not fall into other categories
Projects
None yet
Development

No branches or pull requests

6 participants