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

Support multiple types in Type Query #23264

Closed
m9aertner opened this issue Feb 20, 2017 · 4 comments
Closed

Support multiple types in Type Query #23264

m9aertner opened this issue Feb 20, 2017 · 4 comments

Comments

@m9aertner
Copy link
Contributor

It's a bit inconsistent that for URL queries it's possible to specify multiple types whereas the request body search only supports one single type.

Or maybe that can be done and it's just the documentation that's a bit thin there?

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-type-query.html

Generally, it might make sense to support the same syntax as for multi-index (https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-index.html, exclusion, inclusion, wildcards) also for multi-type? And ideally in both request body (DSL) as well as URL searches?

Example (AWS ES 5.1.1):

curl -XPUT 'http://search-xxx.us-east-1.es.amazonaws.com/myindex/_bulk' -d '
{"index": {"_type": "myType","_id": "1"}}
{"foo":"bar one"}
{"index": {"_type": "myOtherType","_id": "1"}}
{"foo":"bar none"}
'

# multiple types in query URI - OK, two results
curl -XGET 'http://search-xxx.us-east-1.es.amazonaws.com/myindex/myType,myOtherType/_search?q=bar'


# single type in request body - OK, one result
curl -XGET 'http://search-xxx.us-east-1.es.amazonaws.com/myindex/_search' -d '{
  "query" : {
    "type" : { "value" : "myOtherType" }
  }
}'

# multiple types in request body - not supported
curl -XGET 'http://search-xxx.us-east-1.es.amazonaws.com/myindex/_search' -d '{
  "query" : {
    "type" : { "value" : [ "myType", "myOtherType" ] }
  }
}'

# variants don't work, either
## "type" : { "values" : [ "myType", "myOtherType" ]
## "types" : [ "myType", "myOtherType" ] (I think that would be most natural)
## "type" : { "value" : "myType", "value" : "myOtherType" } (strange JSON, last one wins)
@dadoonet
Copy link
Member

Why not wrapping the type queries within a bool query and 2 should clauses?
Would that work for you?

@m9aertner
Copy link
Contributor Author

Good idea. I will try that and post if it works, Thanks for the pointer.

@m9aertner
Copy link
Contributor Author

Sure, works. Thanks. Closing.

{
  "query": {
    "bool": {
      "must": {
        "term": { "foo": "bar" }
      },
      "filter": {
        "bool": {
          "should": [
            { "type": { "value": "myType" } },
            { "type": { "value": "myOtherType" } }
          ]
        }
      }
    }
  }
}

@clintongormley
Copy link

also note that we're planning on removing types: #15613

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants