Skip to content

How to use the MultiTermVectorsAsync API #3219

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

Closed
aelghoneimy opened this issue Apr 27, 2018 · 3 comments
Closed

How to use the MultiTermVectorsAsync API #3219

aelghoneimy opened this issue Apr 27, 2018 · 3 comments

Comments

@aelghoneimy
Copy link

NEST/Elasticsearch.Net version: 6.0.2

Elasticsearch version: 6.2.3

Description of the problem including expected versus actual behavior:
I am trying to call the below query using NEST

GET 123_original/_doc/_mtermvectors
{
  "ids": [
    "9a271078-086f-4f4b-8ca0-16376c2f49a7",
    "481ce3db-69bf-4886-9c38-fcb878d44925"
  ],
  "parameters": {
    "fields": ["*"],
    "positions": false,
    "offsets": false,
    "payloads": false,
    "term_statistics": false,
    "field_statistics": false
  }
}

The NEST API (I think) would look something like this

var term = await elasticClient.MultiTermVectorsAsync(x =>
{
    return x.Index(indexOriginal)    // 123_original
        .Type(typeName)              // _doc
        .GetMany<ElasticDataSet>(ids.Keys) // list of strings
        .Fields("*")
        .FieldStatistics(false)
        .Positions(false)
        .Offsets(false)
        .TermStatistics(false)
        .Payloads(false);
});

The problem is that the above API is returning the following error
Index name is null for the given type and no default index is set. Map an index name using ConnectionSettings.DefaultMappingFor<TDocument>() or set a default index using ConnectionSettings.DefaultIndex().

And this is the query that its trying to execute which has the index in it and is missing the ids, but works in Kibana when the ids are set.
123_original/_doc/_mtermvectors?fields=%2A&field_statistics=false&positions=false&offsets=false&term_statistics=false&payloads=false

I cannot find a documentation on how to use the Multi Term Vector using NEST.

related Stackoverflow issue: https://stackoverflow.com/questions/50058822/how-to-use-multitermvectorsasync

@russcam
Copy link
Contributor

russcam commented Aug 28, 2018

Apologies for the late response @AymanGaafar.

The Multi Term Vectors API within NEST does not expose the ability to set only Ids, it always assumes that you are passing "docs":

[JsonProperty("docs")]
IEnumerable<IMultiTermVectorOperation> Documents { get; set; }

Even when passing

client.MultiTermVectors(mt => mt
    .Index("123_original")
    .Type("_doc")
    .GetMany<object>(ids)
    .Fields("*")
    .Positions(false)
    .Offsets(false)
    .Payloads(false)
    .TermStatistics(false)
    .FieldStatistics(false)
);

The _index and _type for each id is inferred from object in GetMany<T>

POST http://localhost:9200/123_original/_doc/_mtermvectors?pretty=true&fields=*&positions=false&offsets=false&payloads=false&term_statistics=false&field_statistics=false 
{
  "docs": [
    {
      "_index": "users",
      "_type": "object",
      "_id": "9a271078-086f-4f4b-8ca0-16376c2f49a7"
    },
    {
      "_index": "users",
      "_type": "object",
      "_id": "481ce3db-69bf-4886-9c38-fcb878d44925"
    }
  ]
}

I think we can expose this in a more consumable way within the client in the future.

The good news is that you can submit the exact query that you would like with the low level client exposed on IElasticClient, and still get back a high level response

MultiTermVectorsResponse response = 
    client.LowLevel.Mtermvectors<MultiTermVectorsResponse>("123_original", "_doc", PostData.Serializable(new 
    { 
        ids = ids,
        parameters = new
        {
            fields = new[] { "*" },
            positions = false,
            offsets = false,
            payloads = false,
            term_statistics = false,
            field_statistics = false
        }
    }));

which will send the following request:

POST http://localhost:9200/123_original/_doc/_mtermvectors?pretty=true 
{
  "ids": [
    "9a271078-086f-4f4b-8ca0-16376c2f49a7",
    "481ce3db-69bf-4886-9c38-fcb878d44925"
  ],
  "parameters": {
    "fields": [
      "*"
    ],
    "positions": false,
    "offsets": false,
    "payloads": false,
    "term_statistics": false,
    "field_statistics": false
  }
}

russcam added a commit that referenced this issue Aug 29, 2018
This commit adds support for providing a set of Ids to MultiTermVectors API to be used in
conjunction with index and type provided in the URI.

Index() and Type() methods added to MultiTermVectorOperation to allow the default typeof(T)
values to be overidden.

Closes #3219
@russcam
Copy link
Contributor

russcam commented Aug 29, 2018

I've opened #3382 to address

russcam added a commit that referenced this issue Aug 29, 2018
This commit adds support for providing a set of Ids to MultiTermVectors API to be used in
conjunction with index and type provided in the URI.

Index() and Type() methods added to MultiTermVectorOperation to allow the default typeof(T)
values to be overidden.

Closes #3219
Mpdreamz pushed a commit that referenced this issue Sep 3, 2018
This commit adds support for providing a set of Ids to MultiTermVectors API to be used in
conjunction with index and type provided in the URI.

Index() and Type() methods added to MultiTermVectorOperation to allow the default typeof(T)
values to be overidden.

Closes #3219
Mpdreamz pushed a commit that referenced this issue Sep 3, 2018
This commit adds support for providing a set of Ids to MultiTermVectors API to be used in
conjunction with index and type provided in the URI.

Index() and Type() methods added to MultiTermVectorOperation to allow the default typeof(T)
values to be overidden.

Closes #3219
@aelghoneimy
Copy link
Author

Thanks @russcam, make sense now

@Mpdreamz Mpdreamz mentioned this issue Sep 10, 2018
45 tasks
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