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

Adding support for fields option in search query. #29

Open
mattjanssen opened this issue Oct 11, 2023 · 1 comment
Open

Adding support for fields option in search query. #29

mattjanssen opened this issue Oct 11, 2023 · 1 comment

Comments

@mattjanssen
Copy link

The fields options for limiting a search response was introduced in version 7.10 and is documented here.

If I were to create a PR, would it be as simple as updating the ONGR\ElasticsearchDSL\Search class? Thanks!

@hkulekci
Copy link

Hello @mattjanssen, I guess this also needs support for both versions 8.x and 7.x. I'm happy to help you if you need support or a review for PR.

While implementation, let's think about the inner_hits too. Here is a sample using fields with inner_hits :

PUT sample
{
  "mappings": {
    "properties": {
      "users": {
        "type": "nested"
      }
    }
  }
}

POST sample/_doc
{
  "id": 3,
  "users": [
    {
      "id": 1,
      "name": "Foo 1"
    },
    {
      "id": 2,
      "name": "Foo 2"
    },
    {
      "id": 3,
      "name": "Foo 4"
    }
  ]
}

GET sample/_search
{
  "_source": ["id"], 
  "query": {
    "nested": {
      "path": "users",
      "inner_hits": {
        "fields": ["users.id", "users.name"]
      }, 
      "query": {
        "term": {
          "users.id": {
            "value": "1"
          }
        }
      }
    }
  }
}

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

2 participants