Comments (4)
Thank you! Just a not for posterity, one still needs to use the parseEsResponse
helper, since on full-batch level errors, ES still returns that kind of error.
from bloodhound.
FYI sketch of something:
data BulkResponse = BulkResponse
{ bulkTook :: Int
, bulkErrors :: Bool
, bulkActionItems :: [BulkActionItem]
}
deriving (Show, Generic)
data BulkActionItem = BulkActionItem
{ baiAction :: BulkAction
, baiItem :: BulkItem
}
deriving (Show, Generic)
data BulkItem = BulkItem
{ biIndex :: Text
, biId :: Text
, biStatus :: Maybe Int
, biError :: Maybe BulkError
}
deriving (Show, Generic)
data BulkAction = Index | Create | Delete | Update
deriving (Show, Generic)
data BulkError = BulkError
{ beType :: Text
, beReason :: Text
}
deriving (Show, Generic)
instance FromJSON BulkResponse where
parseJSON = withObject "BulkResponse" $ \o ->
BulkResponse <$> o .: "took" <*> o .: "errors" <*> o .: "items"
instance FromJSON BulkActionItem where
parseJSON j =
parseItem Index j
<|> parseItem Create j
<|> parseItem Delete j
<|> parseItem Update j
where
-- | The object has a single key: value pair, where the key encodes
-- the action.
parseItem :: BulkAction -> A.Value -> A.Parser BulkActionItem
parseItem action = withObject "BulkActionItem" $ \o -> do
v <- o .: toS actionText
pure $! BulkActionItem { baiAction = action, baiItem = v }
where
actionText :: Text
actionText = case action of
Index -> "index"
Create -> "create"
Delete -> "delete"
Update -> "update"
instance FromJSON BulkItem where
parseJSON = withObject "BulkItem" $ \o ->
BulkItem
<$> o
.: "_index"
<*> o
.: "_id"
<*> o
.:? "status" -- allegedly present but ES example shows a case where it is missing.. so..
<*> o
.:? "error"
instance FromJSON BulkError where
parseJSON = withObject "BulkError"
$ \o -> BulkError <$> o .: "type" <*> o .: "reason"
testErrorBody :: Text
testErrorBody = [text|
{"took":0,"errors":true,"items":[{"index":{"_index":"theidx","_type":"_doc","_id":"some:id:1","status":429,"error":{"type":"cluster_block_exception","reason":"index [theidx] blocked by: [TOO_MANY_REQUESTS/12/disk usage exceeded flood-stage watermark, index has read-only-allow-delete block];"}}}]}
|]
testSuccessBody :: Text
testSuccessBody = [text|
{"took":7, "errors": false, "items":[{"index":{"_index":"test","_id":"1","_version":1,"result":"created","forced_refresh":false}}]}
|]
Feel free to use.
from bloodhound.
Thanks for your report and your contribution, I'll have a look tomorrow.
from bloodhound.
I have pushed it! Thanks a lot!
from bloodhound.
Related Issues (20)
- ES 6.4.2 HOT 9
- About Mappings HOT 2
- DocId needs url-encoding for certain operations HOT 7
- Docker Compose support so that full test runs can be spun up
- Re-unifying Bloodhound's implementation HOT 4
- Update to Elastic 7.x (currently 7.4)
- Support count API HOT 1
- Is it possible to use a later version of containers and http-client HOT 2
- Derive Mapping
- Support GHC 8.8 HOT 1
- Update docs at Hackage
- Latest version low upper cap HOT 2
- Build errors with `aeson-2.0.1.0` HOT 1
- In nix stable and unstable, bloodhound is tagged as "broken" HOT 4
- Search parameter `min_score` is not supported
- Library redesign HOT 1
- Not possible to build with http-client >= 0.7 HOT 2
- Add example that deserializes response from ES HOT 2
- `parseEsResponse` not able to parse a "document not found" response HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bloodhound.