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

SourceIncludes does not appear to work and is not including specified Fields in the query #8400

Open
ahazelwood opened this issue Nov 12, 2024 · 0 comments
Labels
8.x Relates to 8.x client version Category: Bug

Comments

@ahazelwood
Copy link

Elastic.Clients.Elasticsearch version: 8.15.10

Elasticsearch version: 8.15.1

.NET runtime version: 8.0

Operating system version: Windows 12

Description of the problem including expected versus actual behavior:
A clear and concise description of what the bug is.

In the previous NEST client, I could issue a query like:

                search = search.Source(s => s
                    .Includes(i => i
                        .Fields(
                            f => f.Id,
                            f => f.Title
                        )
                    )
                );

and the resulting json would look like:

{
    "aggs": {
        "category": {
            "terms": {
                "field": "category",
                "min_doc_count": 0,
                "size": 2147483647
            }
        },
        "stream": {
            "terms": {
                "field": "stream",
                "min_doc_count": 0,
                "size": 2147483647
            }
        },
        "entity": {
            "terms": {
                "field": "entity",
                "min_doc_count": 0,
                "size": 2147483647
            }
        },
        "folder": {
            "terms": {
                "field": "folder",
                "min_doc_count": 0,
                "size": 2147483647
            }
        },
        "label": {
            "terms": {
                "field": "label",
                "min_doc_count": 0,
                "size": 2147483647
            }
        },
        "language": {
            "terms": {
                "field": "language",
                "min_doc_count": 0,
                "size": 2147483647
            }
        },
        "metadata": {
            "terms": {
                "field": "metadata",
                "min_doc_count": 0,
                "size": 2147483647
            }
        },
        "rating": {
            "terms": {
                "field": "rating",
                "min_doc_count": 0,
                "size": 2147483647
            }
        },
        "tag": {
            "terms": {
                "field": "tag",
                "min_doc_count": 0,
                "size": 2147483647
            }
        }
    },
    "from": 0,
    "query": {
        "query_string": {
            "default_operator": "and",
            "query": "projectId:2334"
        }
    },
    "size": 1000,
    "sort": [
        {
            "approved": {
                "order": "desc"
            }
        },
        {
            "_score": {
                "order": "desc"
            }
        },
        {
            "rating": {
                "order": "desc"
            }
        }
    ],
    "_source": {
        "includes": [
            "id",
            "title"
        ]
    },
    "track_total_hits": true
}

In the new ElasticSearch client (after searching through various issues, as well as the code), I am trying to replicate this like the following, but am not getting the includes in the resulting json.

                search = search.SourceIncludes(Fields.FromFields([
                    Infer.Field<SearchAlert>(f => f.Id), Infer.Field<SearchAlert>(f => f.Title)
                ]));

{
    "aggregations": {
        "category": {
            "terms": {
                "field": "category",
                "min_doc_count": 0,
                "size": 2147483647
            }
        },
        "stream": {
            "terms": {
                "field": "stream",
                "min_doc_count": 0,
                "size": 2147483647
            }
        },
        "entity": {
            "terms": {
                "field": "entity",
                "min_doc_count": 0,
                "size": 2147483647
            }
        },
        "folder": {
            "terms": {
                "field": "folder",
                "min_doc_count": 0,
                "size": 2147483647
            }
        },
        "label": {
            "terms": {
                "field": "label",
                "min_doc_count": 0,
                "size": 2147483647
            }
        },
        "language": {
            "terms": {
                "field": "language",
                "min_doc_count": 0,
                "size": 2147483647
            }
        },
        "metadata": {
            "terms": {
                "field": "metadata",
                "min_doc_count": 0,
                "size": 2147483647
            }
        },
        "rating": {
            "terms": {
                "field": "rating",
                "min_doc_count": 0,
                "size": 2147483647
            }
        },
        "tag": {
            "terms": {
                "field": "tag",
                "min_doc_count": 0,
                "size": 2147483647
            }
        }
    },
    "from": 0,
    "query": {
        "query_string": {
            "default_operator": "and",
            "query": "projectId:2423"
        }
    },
    "size": 1000,
    "sort": [
        {
            "approved": {
                "order": "desc"
            }
        },
        {
            "_score": {
                "order": "desc"
            }
        },
        {
            "rating": {
                "order": "desc"
            }
        }
    ],
    "track_total_hits": true
}

Any help would be appreciated as this is one of the last pieces of our client that needs to be updated, and we don't want to bring back all fields from our Search document, but still want to rely upon it for reference within various other Expressions.

@ahazelwood ahazelwood added 8.x Relates to 8.x client version Category: Bug labels Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.x Relates to 8.x client version Category: Bug
Projects
None yet
Development

No branches or pull requests

1 participant