I am trying to implement email search with ElasticSearch.
Here are the example documents.
{
...
"email": "valeri#gmail.com"
},
{
...
"email": "tom#gmail.com"
}
So when I use the match query: { "match": { "email": "valeri#gmail.com"
} }
I get both of "valeri#gmail.com"and "tom#gmail.com" but the result must be only "valeri#gmail.com".
I think it is because of # character.
Any good solution to resolve this issue?
You need to use the Email Tokenizer as specified here:
https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-uaxurlemail-tokenizer.html
Use this to make your request 👍
GET my_index/_search
{
"query": {
"match_phrase_prefix" : {
"email": "valery#gmail.com"
}
}
}
You will have the expecting result
Related
Having a real problem with overriding a field in a data template.
It works fine with top-level JSON fields, but second level or nested fields are out of scope.
I have a request body that looks like this:
{
"method": "validateUserEmail",
"parameters": {
"email": "email#addr.ess"
}
}
stash.addTemplate():
stash.addDataTemplate({
'Generic1ParamRequestBody': {
"method": "validateUserEmail",
"parameters": {
"email": ""
}
}
});
**call to OVERRIDE method field:**
.withJson({
'#DATA:TEMPLATE#': 'Generic1ParamRequestBody',
'#OVERRIDES#': {
'method': 'validateUserEmail' //WORKS
},
**call to OVERRIDE email field: **
.withJson({
'#DATA:TEMPLATE#': 'Generic1ParamRequestBody',
'#OVERRIDES#': {
'email': 'email#addr.ess' //DOESNT WORK
},
**All I get from the above is: **
"body": {
"method": "validateUserEmail",
"parameters": {
"email": ""
},
"email": "auto#api.test"
},
Its like its not smart enough to look for email field on level 2 of nesting.
I've tried jsonpath (parameters.email) and changing the entire parameters field with JSON.stringify(parameters: { email: email#addr.ess}); But no luck at all.
Can anyone spot anything I am missing or doing daftly (instead of deftly)
You are missing the parameters filed.
.withJson({
'#DATA:TEMPLATE#': 'Generic1ParamRequestBody',
'#OVERRIDES#': {
'parameters': {
"email": "abc"
}
}
})
I've been dealing with a project. My goal is to get result from search engine in all circumstances for example, although i enter a keyword which is not include the keys inside data or is a empty string, I still need to get some result.How can i reach my goal?
you can see the query below :
query: {
regexp: {
title: "something to not found .*",
},
Try use "prefix" or "query_string"
You also can use title.keyword for exact value
1 -
{
"query": {
"prefix": {
"title": {
"value": "<data>"
}
}
}
}
2 -
{
"query": {
"query_string": {
"default_field": "title",
"query": "<data>*^0"
}
}
}
I'm using Dynamoose to simplify my interactions with DynamoDB in a node.js application. I'm trying to write a query using Dynamoose's Model.query function that will search a table using an index, but it seems like Dynamoose is not including all of the info required to process the query and I'm not sure what I'm doing wrong.
Here's what the schema looks like:
const UserSchema = new dynamoose.Schema({
"user_id": {
"hashKey": true,
"type": String
},
"email": {
"type": String,
"index": {
"global": true,
"name": "email-index"
}
},
"first_name": {
"type": String,
"index": {
"global": true,
"name": "first_name-index"
}
},
"last_name": {
"type": String,
"index": {
"global": true,
"name": "last_name-index"
}
}
)
module.exports = dynamoose.model(config.usersTable, UserSchema)
I'd like to be able to search for users by their email address, so I'm writing a query that looks like this:
Users.query("email").contains(query.email)
.using("email-index")
.all()
.exec()
.then( results => {
res.status(200).json(results)
}).catch( err => {
res.status(500).send("Error searching for users: " + err)
})
I have a global secondary index defined for the email field:
When I try to execute this query, I'm getting the following error:
Error searching for users: ValidationException: Either the KeyConditions or KeyConditionExpression parameter must be specified in the request.
Using the Dynamoose debugging output, I can see that the query winds up looking like this:
aws:dynamodb:query:request - {
"FilterExpression": "contains (#a0, :v0)",
"ExpressionAttributeNames": {
"#a0": "email"
},
"ExpressionAttributeValues": {
":v0": {
"S": "mel"
}
},
"TableName": "user_qa",
"IndexName": "email-index"
}
I note that the actual query sent to DynamoDB does not contain KeyConditions or KeyConditionExpression, as the error message indicates. What am I doing wrong that prevents this query from being written correctly such that it executes the query against the global secondary index I've added for this table?
As it turns out, calls like .contains(text) are used as filters, not query parameters. DynamoDB can't figure out if the text in the index contains the text I'm searching for without looking at every single record, which is a scan, not a query. So it doesn't make sense to try to use .contains(text) in this context, even though it's possible to call it in a chain like the one I constructed. What I ultimately needed to do to make this work is turn my call into a table scan with the .contains(text) filter:
Users.scan({ email: { contains: query.email }}).all().exec().then( ... )
I am not familiar with Dynamoose too much but the following code below will do an update on a record using node.JS and DynamoDB. See the key parameter I have below; by the error message you got it seems you are missing this.
To my knowledge, you must specify a key for an UPDATE request. You can checks the AWS DynamoDB docs to confirm.
var params = {
TableName: table,
Key: {
"id": customerID,
},
UpdateExpression: "set customer_name= :s, customer_address= :p, customer_phone= :u, end_date = :u",
ExpressionAttributeValues: {
":s": customer_name,
":p": customer_address,
":u": customer_phone
},
ReturnValues: "UPDATED_NEW"
};
await docClient.update(params).promise();
This question is purely syntax. I'm trying to insert a generated JSON object into another JSON object.
Let's say my JSON looks like this:
var database =
{
"john": {
"pwd": "somehashrighthere",
"mail": "example#gmail.com"
}
}
This object stores a hash and an email under the users name. Now I want to insert a new user:
var name = "somename";
var pwd = "hash";
var mail = "email#email.net";
If I try to insert this into a json object as by
database.name =
{
"pwd": pwd,
"mail": mail
}
I would expect an output that fills the gaps:
{
"john": {
"pwd": "r1pper",
"mail": "example#gmail.com"
},
"somenamerighthere": {
"pwd": "hash",
"mail": "email#email.net"
}
}
Instead the javascipt takes the expression quite literall:
{
"john": {
"pwd": "r1pper",
"mail": "example#gmail.com"
},
"name": {
"pwd": "pwd",
"mail": "mail"
}
}
I'm quite new to javascript/json and would appreciate if you guys exlain to me how one could dynamically(!) generate json objects and feed them into a bigger data structure. None of the answers I found on SO could solve this problem in a way I could understand. Do I need to make changes to the datastructure, or have I just misunderstood the javascript/node.js syntax. Thanks in advance :)
Edit: I solved the problem quite simply. Turns out javascript actually passes the variables into the json and I was just confused:
{
"john": {
"pwd": "r1pper",
"mail": "example#gmail.com"
},
"name": {
"pwd": "hash",
"mail": "email#email.net"
}
}
Now we just need to pass the name dynamically, which can be solved by treating the JSON, as if it was an array:
database[name]
treats name as a variable.
Edit 2:
The comments below came in while editing. I apologize for that.
you should use database[name] (take the value of name and use as index)
instead of database.name (use the string 'name' as index)
I am trying to query some data from a contentful API using gatsby's built-in graphiQL.
EDIT: after a suggestion from the comments, I made a introspection query to get the schema information:
{
"name": "contentfulStranNaslovQueryString_2",
"kind": "INPUT_OBJECT"
}
When I run this query:
{
contentfulStran {
id
naslov
}
}
I get the expected result (the first entry for the data model):
{
"data": {
"contentfulStran": {
"id": "c2tD44y2tDe8QC4yqkwMOgo",
"naslov": "Novice"
}
}
}
But now I would like to pass in a query parameter that only gets data specified on the naslov field. I tried this:
{
contentfulStran(naslov: "Ponudba") {
id
naslov
}
}
But I am getting the following error:
{
"errors": [
{
"message": "Argument \"naslov\" has invalid value \"Ponudba\".\nExpected \"contentfulStranNaslovQueryString_2\", found not an object.",
"locations": [
{
"line": 2,
"column": 27
}
]
}
]
}
What am I doing wrong?
Miha answered his own question in the comments. The correct way to filter is:
{
contentfulStran(naslov: {eq: "Ponudba"})
{
id
naslov
zaporedje
tekst
{
tekst
}
}
}
Note the {eq: "param"} object instead of just giving the param.