I've got data that looks like this:
CK/YZfB6XUmSOSM3IJqM2Q; Response code: 404. Elapsed: 0ms. Request: GET /marketing
4kk/TiKjYU2JY0L2N14QLg; Response code: 200. Elapsed: 10ms. Request: GET /api/monitor
vhXVsw4sBk69qv7dGE8JYw; Response code: 404. Elapsed: 0ms. Request: GET /graph-statistics
4kk/TiKjYW2JY0L2N14QLg; Response code: 200. Elapsed: 10ms. Request: GET /api/monitor
I'm trying to query/filter it out so I only remain with the 4xx responses.
I've read the documentation regarding wildcards, so I'd expect at least one of the following queries to work (this is as written in Kibana):
message: "Response code: 4??"
message: 4??.
message: "Response code: 4*"
Here's how these look in JSON, in case escaping matters (I've enumerated all the 3 queries in the same JSON for brevity):
"filter" : [],
"query" : {
"query_string" : {
"query" : "message: \"Response code: 4??\"",
"query" : "message: 4??.",
"query" : "message: \"Response code: 4*\"",
"analyze_wildcard" : true
}
},
I've had no luck so far and I'm running out of ideas...
Based on your question, the text appears to be indexed in the field message.
If you want your query to return only 4XX responses, then try the below query.
message: (Response AND code AND 4??)
This query is essentially asking lucene to get records that have the words response, code and 4xx in them.
I tested against the following case, where your record might contain 400 as part of Elapsed time.
......... Response code:200 Elapsed:404ms.......
But the query works fine and doesn't return these results as the 404 is having ms as suffix. So, this doesn't match with your search for 4??.
Also, you might have to check for how the field is indexed in your collection. Is it stored as text or string?
In your code example, you have not escaped : which is a special character in lucene.
Note: this query checks for presence of these keywords in text but nor necessarily in the given order
Related
I am a very noob and very very very beginner in elastic search, I got this error
StatusCodeError: [illegal_argument_exception] Fielddata is disabled on text fields by default. Set fielddata=true on [time-stamp] in order to load field data in memory by reversing the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.
I saw a few blogs where they mentioned I have to do something like
"field": "user.keyword"
but I tried to put this 1 line snippet in my code, please help me out I don't even know what is field and user in my case/code
my code:
esClient.search({
index:ESindex,
body: {
sort:[{"time-stamp":{"order":"desc"}}],
size:req.query.count,
query: {
match_phrase: { "participant-id":req.query["participant-id"] }
}
}
})
I am trying to get some JSON data from the API provided by the vendor, but i am getting error i try google it, in many comments people say to use JSON.Stringify but in my case JSON.Stringify didnt help me it returns an empty array like {}
repose from the api are as follow
[{ SYMBOL: 'FOREX',
CODE: 'REG',
LST: '219.50',
LTP: '12:52:35'}]
but my desire response is
[{ "SYMBOL" : "FOREX",
"CODE": "REG",
"LTP": '219.50',
"LST": '12:52:35'}]
If the JSON result provided by the vendor's API is indeed this :
[{ SYMBOL: 'FOREX',
CODE: 'REG',
LST: '219.50',
LTP: '12:52:35'}]
I have to inform you that this is invalid JSON. In JSON, the properties should be strings between double-quotes, otherwise it cannot be parsed.
Your desired response is the correct form. There is likely an error in the way the vendor is forming the output.
tl;dr : Your vendor's API is giving you a JavaScript Object, not JSON.
Your response is on text, To convert text to JSON string,
let text = `[{ SYMBOL: 'FOREX',
CODE: 'REG',
LST: '219.50',
LTP: '12:52:35'}]`
let jsonStr = JSON.stringify(eval("(" + text + ")")); // Convert Object String to JSON
console.log(jsonStr);
Note : Make sure that your vendor is trusted source, Because eval opens up your code for injection attacks, If your are worry about this, Please contact your vendor to provide JSON response.
Reference : Convert object string to JSON
Ok so what i did is use STRINGFY as a middleware and that solve my problem thanks for your help guys really appreciatable.
I have a json document in my DB that looks like this :
{
"uri" : "/me/myself/and/bd1e0f91656bfc713eb6560eeaad7ad1.json",
"category" : "content",
"format" : "json",
"versionId" : "14697362595356370",
"contentType" : "application/json",
"contentLength" : "1938",
"collections" : ["http://me.myself.com/collectionA"],
"properties" : {
"relatives" : ["/me/myself/and/B.json", "/me/myself/and/A.json"]
},
"content":{}
}
I'm trying to get all documents that have a specific relative in the properties:
qb.where(
qb.scope(
qb.property('relatives'),
qb.word("/me/myself/and/B.json"),
qb.fragmentScope('properties')
))
But i keep getting a large set of document that doesn't fit the query.
Any idea how to do this using the Marklogic NodeJS API?
I see two things that look like they might be problems. The first is qb.fragmentScope('properties'). This tells MarkLogic to look in the document's properties, rather than the document's content. That doesn't look like what you meant, given your sample JSON document.
The second problem is the word query -- "/me/myself/and/B.json" is likely being broken up into its constituent words (me, myself, and, B, json), which are then matching in other documents. You want to match exactly what's there, so try a value query:
qb.where(
qb.scope(
qb.properties('properties'),
qb.value('relatives', '/me/myself/and/B.json')
)
)
Note that the qb.scope and the qb.properties are to restrict the search to just match the value when it appears in relatives under a properties JSON property. This is different from the JSON property-versus-content point made above.
qb.where(
qb.propertiesFragment(
qb.term('/me/myself/and/B.json')
)
)
This worked for me.
My question is related to this
findAndModify Error in mongodb - nodejs - error code 17287
But the solution hasn't worked (i tried specify the order but i get the same error) I think it might be something along the lines of the index I am using example instead of _id (_id is a field in this collection I just don't want to search by _id in this case) not sure at all...
The Error:
{ [MongoError: exception: nextSafe(): { $err: "Can't canonicalize query: BadValue bad sort specification", code: 17287 }]
name: 'MongoError',
message: 'exception: nextSafe(): { $err: "Can\'t canonicalize query: BadValue bad sort specification", code: 17287 }',
errmsg: 'exception: nextSafe(): { $err: "Can\'t canonicalize query: BadValue bad sort specification", code: 17287 }',
code: 13106,
ok: 0 }
This is my code, it should find and modify (and return using new:true) the first instance of a document that has the field example equal to minus one.
db.collection('documents').findAndModify({example:-1},{$set:{example:0}},{new:true},function(err,result){
console.dir(err||result);
});
But all it does is error like it hates my face!
Here is a document:
{'_id':0,'example':-1}
My id field is custom numerical Where I ensure the _id is always unique (For my purposes I cannot change the _id to standard mongodb way.)
It was painful to get this to work as the node docs end abruptly and then you are left guessing on how the code structure should be on what would/could of just been a standard structure but isn't! I have wasted a day thanks to the devs undocumented methods.
Here is the working code
db.collection('documents').findAndModify({'example':{$eq:-1}},[['example',1]],{$set:{'example':-1}},{'new':true},function(err,result){
console.dir(err||result);
});
I am not sure I really like writing code like this ether. I might look for another node module for this as the query above looks disgusting!
Would be greate if I could find something that looks as simple as this:
db.collection('documents').findModifyReturn('find:example==-1;order:asc;set:example=0;',function(e,r){});
Try using the $eq operator.
db.collection('documents').findAndModify({example: {$eq: -1}}, {'example', 'ascending'},{$set:{example:0}},{new:true},function(err,result){
console.dir(err||result);
});
Is there a possibility in CouchDB to retrieve a single value from a document? For example, I have a document with 10000 keys like this:
{
"_id": "8098091cc795acde43cd45335373cc92",
"_rev": "2-6d2e0ac43618388cc958b91e5015bba5",
"1":"some value",
"2":"another value",
...
"10000":"last value"
}
and I don't want to parse the whole document each time but just want to get a value of key "2". Is this possible?
EDIT:
Of course, before asking this question I looked through the docs and googled around this but haven't found such possibility. But I'm wondering why this is not possible? In my understanding it is not too much difference between view and document since both of them are sets of key-value pairs, but it is possible to get single value from view using ?key=... in the query string and not possible to do the same for document. Why?
You can use a CouchDB show function to process a document on the server and send arbitrary data to the client. Show functions can do simple things like extracting a single value from the document; or they can convert to a completely different content-type such as XML.
For example:
In database db
which has design document _design/example with show function one_field
you want to fetch document with ID doc_id
but only retrieve the field some_field which has a value "I am the some_field value!"
That query would be:
GET /db/_design/example/_show/one_field/doc_id?name=some_field
The show function would look like this:
function(doc, req) {
// _show function to extract one field
var field_name = req.query.name; // Set to e.g. "some_field"
var field_value = doc[field_name];
return { "code": 200 // HTTP status code
, "headers": // Response headers
{ "content-type": "text/plain" }
, body: field_value
};
}
The design document would look like this:
{ "_id": "_design/example"
, "shows":
{ "one_field": ... } // Paste the above function as a string.
}
CouchDB will return
HTTP 200 OK
Content-Type: text/plain
Content-Length: 26
I am the some_field value!
No. CouchDB is a document oriented DB, so it doesn't support more granular access to the data beyond the overall document itself.
It gives you fine grained indexing, but not actual access.