Ahasanul Haque
Ahasanul Haque

Reputation: 11134

Why elasticsearch indexing work so weirdly?

I was trying to index some data with elastic search, and faced a strange behavior.

If my code is:

import requests
#data = {'key': 'value'}
data = {'v': 'pf'}
#data = generate_document()
print(data)
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
r = requests.post('http://localhost:9200/qa/_doc', data=json.dumps(data), headers=headers)
print(r.status_code)

I get 201 as response code.

But if I have data = {'va': 'pf'}, for some reason I get 400 status code.

Why do these weird things happen?

Basically I want to randomly generate data and index it. Most of the time it throws 400. But regular things like data = {"key": "value"} works.

Upvotes: 0

Views: 194

Answers (2)

LhasaDad
LhasaDad

Reputation: 2133

Likely the status code 400 could have multiple causes:

  1. could be caused my the mappings.dynamic set to strict
  2. could be caused by exceeding 1000 fields in the index.

There may be others.

Upvotes: 1

UWTD TV
UWTD TV

Reputation: 910

Try:

import requests
#data = {'key': 'value'}
data = {'v': 'pf'}
#data = generate_document()
print(data)
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
r = requests.post('http://localhost:9200/qa/_doc', json=data, headers=headers)

Upvotes: 1

Related Questions