Skip to content

Indexed document as string try as object #1747

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
AColmant opened this issue Jan 21, 2016 · 3 comments
Closed

Indexed document as string try as object #1747

AColmant opened this issue Jan 21, 2016 · 3 comments

Comments

@AColmant
Copy link

Hello,

I try to push some json data as in this exemple :

string data = "{ \"source\":\"my_source\", \"country\":\"my_country\", \"company\":\"my_company\" }";

_client.Index(data, s => s
    .Index("my_index")
    .Type("my_type")
    .Id(Guid.NewGuid().ToString()));
}

Currently (with the master branch 2.0), this does not work for me.
When running, I could notice that the constructor Elasticsearch.Net.PostData(T item) is called instead of (in my humble opinion) Elasticsearch.Net.PostData(string item). So the execution try to serialize a string...

I found a unit test only related with a document as object but not with byte[], string, IEnumerable<string> item, IEnumerable<object> item to confirm this.

NB : Without s.id() the request sent is not POST (and is therefore considered as false by ElasticSearch) but perhaps this is result of the unexpected execution described above.

@Mpdreamz
Copy link
Member

Are you on the latest alpha2 the Id bug should have been fixed as per: #1736

I suspect _client is a NestClient which does not support posting strings directly. You need to use the LowLevel client which you can get to using .Raw

_client.Raw.Index<IndexResponse>("index", "type", "{}");

@AColmant
Copy link
Author

Oh! Yes, I tried Id in alpha1 and I haven't try again in alpha2. My mistake, thank you.

Ok, I just test your advice, they seem to work. I'm just sorry for not having found documentation related to this. But it's really good job, thank you guys for all.

@Mpdreamz
Copy link
Member

No worries thanks for taking the alpha for a spin, feel free to open more tickets! 👍

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