Elastic search always return no result - amazon-web-services

I am trying to test elastic search with the following instruction:
http://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-gsg.html
When I try the above and upload the following text which is also in the instruction:
{
"index": {
"_index": "movies",
"_type": "listings",
"_id": "2"
}
} {
"director": "Frankenheimer, John",
"genre": ["Drama", "Mystery", "Thriller"],
"year": 1962,
"actor": ["Lansbury, Angela", "Sinatra, Frank", "Leigh, Janet", "Harvey, Laurence", "Silva, Henry", "Frees, Paul", "Gregory, James", "Bissell, Whit", "McGiver, John", "Parrish, Leslie", "Edwards, James", "Flowers, Bess", "Dhiegh, Khigh", "Payne, Julie", "Kleeb, Helen", "Gray, Joe", "Nalder, Reggie", "Stevens, Bert", "Masters, Michael", "Lowell, Tom"],
"title": "The Manchurian Candidate"
} {
"index": {
"_index": "movies",
"_type": "listings",
"_id": "3"
}
} {
"director": "Baird, Stuart",
"genre": ["Action", "Crime", "Thriller"],
"year": 1998,
"actor": ["Downey Jr., Robert", "Jones, Tommy Lee", "Snipes, Wesley", "Pantoliano, Joe", "Jacob, Ir\u00e8ne", "Nelligan, Kate", "Roebuck, Daniel", "Malahide, Patrick", "Richardson, LaTanya", "Wood, Tom", "Kosik, Thomas", "Stellate, Nick", "Minkoff, Robert", "Brown, Spitfire", "Foster, Reese", "Spielbauer, Bruce", "Mukherji, Kevin", "Cray, Ed", "Fordham, David", "Jett, Charlie"],
"title": "U.S. Marshals"
} {
"index": {
"_index": "movies",
"_type": "listings",
"_id": "4"
}
} {
"director": "Ray, Nicholas",
"genre": ["Drama", "Romance"],
"year": 1955,
"actor": ["Hopper, Dennis", "Wood, Natalie", "Dean, James", "Mineo, Sal", "Backus, Jim", "Platt, Edward", "Ray, Nicholas", "Hopper, William", "Allen, Corey", "Birch, Paul", "Hudson, Rochelle", "Doran, Ann", "Hicks, Chuck", "Leigh, Nelson", "Williams, Robert", "Wessel, Dick", "Bryar, Paul", "Sessions, Almira", "McMahon, David", "Peters Jr., House"],
"title": "Rebel Without a Cause"
}
After when I use this command :
curl -XGET 'search-movies-4f3nw7eiia2xiynjr55a2nao2y.us-west-1.es.amazonaws.com/movies/_search?q=Frankenheimer'
I never get anything back. always returns 0. Here is what I get back:
I am not if I am doing it right but I think I should be able to see at least something because I have Frankenheimer in the director key of the json data uploaded. Can anyone shed light on it?

Try searching the whole index with curl -XGET search-movies-4f3nw7eiia2xiynjr55a2nao2y.us-west-1.es.amazon‌​aws.com/movies/_sear‌​ch which will return the first 10 results by default. If it returns less than 10, the data is likely not in the index.
You can verify that by changing the query to:
curl -XGET search-movies-4f3nw7eiia2xiynjr55a2nao2y.us-west-1.es.amazon‌​aws.com/movies/_sear‌​ch?q=director:Burton
Check out the Elasticsearch URI Search for the complete list of the parameters.

Related

Secondary Index not working for Database using #key

I should get the DynamoDb id for Justin. The call doesn't seem to fail. If i console.log(returned) i get an [object Object]. When i try to get to the returned.data.getIdFromUserName.id or returned.data.getIdFromUserName.email (anything else in the table) i get undefined. What am i missing?
Returned data:
{
"data": {
"getIdFromUserName": {
"items": [
{
"id": "3a5a2ks4-f137-41e2-a604-594e0c52a298",
"userName": "Justin",
"firstname": "null",
"weblink": "#JustinTimberlake",
"email": "iuiubiwewe#hotmail.com",
"mobileNum": "+0123456789",
"profilePicURI": "null",
"listOfVideosSeen": null,
"userDescription": "I wanna rock your body, please stay",
"isBlocked": false,
"GridPairs": null
}
],
"nextToken": null
}
}
}
I'd suggest getting a better idea of what console.log(returned) is printing.
Try console.log(JSON.stringify(returned, null, 2)) to inspect what is being returned.
EDIT: The data you're working with looks like this:
{
"data": {
"getIdFromUserName": {
"items": [
{
"id": "3a5a2ks4-f137-41e2-a604-594e0c52a298",
"userName": "Justin",
"firstname": "null",
"weblink": "#JustinTimberlake",
"email": "iuiubiwewe#hotmail.com",
"mobileNum": "+0123456789",
"profilePicURI": "null",
"listOfVideosSeen": null,
"userDescription": "I wanna rock your body, please stay",
"isBlocked": false,
"GridPairs": null
}
],
"nextToken": null
}
}
}
Pay close attention to the structure of that response. Both data and getIdFromUserName are maps. The content of data.getIdFromUserName is an array named items. Therefore, data.getIdFromUserName.items is an array containing the results of your query. You'll need to iterate over that array to get the data you are looking for.
For example, data.getIdFromUserName.items[0].id would be 3a5a2ks4-f137-41e2-a604-594e0c52a298
To access the email it would be data.getIdFromUserName.items[0].email.

Instagram Basic API: Is it possible to get the media_url from "CAROUSEL_ALBUM" in one query?

If you are reading this, you will read that you can add children to the fields query parameter. That means that if you have a media with the type "CAROUSEL_ALBUM" you will get the ids of the images as well.
Example CURL:
https://graph.instagram.com/me?access_token=<mytoken>&fields=id,media_type,media_url,children
The result:
...
"id": "some-id",
"media_type": "CAROUSEL_ALBUM",
"media_url": "some-url",
"children": {
"data": [
{
"id": "another-id"
},
{
"id": "other-id"
}
]
}
...
Is it possible to add media_url to the children's data? I don't really want to fetch everything in a loop...
#Mecha I did this for PHP, but maybe you can read this
/**
* Fetches media from the user
*
*/
public function fetchUserMedia(array $options, int $limit = 24): object
{
$query = http_build_query(array_merge([
'limit' => $limit,
'fields' => 'username,caption,id,media_type,media_url,thumbnail_url,children{media_url,thumbnail_url}',
'access_token' => $this->token
], $options));
return json_decode((string) ($this->client->get("https://graph.instagram.com/me/media?{$query}"))->getBody());
}
One output example is like this:
{
"caption": "I\u2018m addicted to chia pudding, how about you? \ud83d\ude0d Layers of zingy lemon vanilla chia pudding, mango thyme infused coconut yoghurt and juicy fresh mango roses. \ud83e\udd24\nMade by \u0040addictedtodates \ud83c\udf4b\u2063\u2063\n\u2063\u2063\u2800\nAND now to our tagged picture of today \ud83d\ude0b\ud83d\ude0b Swipe left to see \u0040smoothie_yumm\u2019s coconut vanilla smoothie bowl topped with turmeric chia pudding \ud83e\udd29\n\u2800\nYou can find the recipe on her page \ud83d\udc9b\n\u2800\n\ud83c\udf31 Tag #avidofood or\u00a0\u0040avidofood\u00a0to be featured in the future!\n\u2800\n\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\u22c6\n#vegan #veganfood #veganfoodie #veganfoodshare #vegatarisch #veganpasta #vegandinner #veganeats #healthyfood #plantbased #plantbasedfood #veganpower #plantbaseddiet #veganiseasy #whatveganseat #forksoverknives #vegetarianrecipes #veganinspo #vegetarian #veganism #veganmeals #veganlife #veganlifestyle #veganlove #veganmealprep #veganrecipes #veganhealth #veganlunch",
"id": "18039820117203997",
"media_type": "CAROUSEL_ALBUM",
"media_url": "https://scontent.xx.fbcdn.net/v/t51.2885-15/71511404_203552310658678_3865693276191599368_n.jpg?_nc_cat=100&_nc_oc=AQlet8stFGS32TTdBhXT4NNfpzd8eNq7oI0xilix4qyiVvt50avuk6RVotMgM-BUptmCrsVwLCGkPCc-sL7b-eAy&_nc_ht=scontent.xx&oh=f1a700b4d021d2d577d54cd74f4838fa&oe=5E534677",
"permalink": "https://www.instagram.com/p/B3-XRMOIWPW/",
"username": "avidofood",
"children": {
"data": [
{
"media_url": "https://scontent.xx.fbcdn.net/v/t51.2885-15/71511404_203552310658678_3865693276191599368_n.jpg?_nc_cat=100&_nc_oc=AQlet8stFGS32TTdBhXT4NNfpzd8eNq7oI0xilix4qyiVvt50avuk6RVotMgM-BUptmCrsVwLCGkPCc-sL7b-eAy&_nc_ht=scontent.xx&oh=f1a700b4d021d2d577d54cd74f4838fa&oe=5E534677",
"id": "18041124712207922"
},
{
"media_url": "https://scontent.xx.fbcdn.net/v/t51.2885-15/72483636_1251439178368296_6758852942587086206_n.jpg?_nc_cat=109&_nc_oc=AQmVrktP2g7Z72WifVdu4z17OzwM7ZNFLln1e1ZQxjdUi-j79Ttf-i840mjYkOb-TW3Dwm39Gyoe3EefxwB7UydW&_nc_ht=scontent.xx&oh=a07d3f51aa5eb5eb30697c4ad25d4e35&oe=5E60AEC3",
"id": "17851162897631131"
}
]
}
You just need to nest the fields in the children query params
/media?fields=id,media_url,children{media_url}&access_token=

Creating a json database with user input

I need to create my .json array to look like this:
{
"airports": [{
"address": "Horley, Gatwick RH6 0NP, UK",
"city": "London",
"shortVersion": "LGW"
},
{
"address": "Marupe, LV-1053",
"city": "Riga",
"shortVersion": "RIX"
}
]
}
But I have it looking right now like this:
{
"airports": {
"(LGW)": {
"address": "Horley, Gatwick RH6 0NP, UK",
"city": "London",
"shortVersion": "(LGW)"
},
"(RIX)": {
"address": "Marupe, LV-1053",
"city": "Riga",
"shortVersion": "(RIX)"
}
}
}
The code I have for user input right now is this:
airports["airports"][inputShortVersion]["shortVersion"] = inputShortVersion;
airports["airports"][inputShortVersion]["city"] = inputCity;
airports["airports"][inputShortVersion]["address"] = inputAddress;
I've searched for a whole day on how to do this, but closest I got to was where it does create the above array but after input it overwrites the last airport data.
I'm using nlohmann json library.
You have a sequence container in your desired output, but associative container in your code.
Try something like
json inputAirport;
inputAirport["shortVersion"] = inputShortVersion;
inputAirport["city"] = inputCity;
inputAirport["address"] = inputAddress;
airports["airports"].push_back(inputAirport);
Apparently, you are creating a json object instead of a json array. To get an array, you could try along the lines of the following:
airports["airports"] = nlohmann::json::array()
new_airport = nlohmann::json::object()
new_airport["shortVersion"] = inputShortVersion;
new_airport["city"] = inputCity;
new_airport["address"] = inputAddress;
airports["airports"].emplace_back(new_airport);
This can be written shorter with braced initalizer lists at the cost of readability:
airports["airports"] = nlohmann::json::array()
airports["airports"].emplace_back(
{
{"shortVersion", inputShortVersion},
{"city", inputCity},
{"address", inputAddress}
});

autofilling a dict python 2.x

I'm quite new to Python and programming in general, so apologies if this is quite basic or has been asked and answered before. Here is a sample of the data I'm working with:
{
"homeTeam": {
"formation": [
"4",
"4",
"2"
],
"lineupsSorted": [
{
"player": {
"name": "Scott P. Brown",
"slug": "scott-p-brown",
"shortName": "S. P. Brown",
"id": 19889,
"hasImage": true
},
"position": 1,
"shirtNumber": 1,
"substitute": false,
"positionName": "Goalkeeper",
"positionNameshort": "G",
"captain": false
},
{
"player": {
"name": "Carl Winchester",
"slug": "carl-winchester",
"shortName": "C. Winchester",
"id": 110785,
"hasImage": true
},
"position": 2,
"shirtNumber": 27,
"substitute": false,
"positionName": "Midfielder",
"positionNameshort": "M",
"captain": false
},
I am looking to automate populating defined names as I have done manually here:
hometeamPositions =['Goalkeeper','Midfielder','Defender','Defender','Defender','Midfielder','Midfielder','Midfielder','Midfielder','Forward','Forward','Goalkeeper','Defender','Defender','Midfielder','Midfielder','Forward','Forward']
hometeamPlayers = ['S. P. Brown','C. Winchester','M. Onariase','W.
Boyle','J. Cranston','H. Pell','J. Rowe','K. Storer','B. Waters','D.
Wright','D. Holman','R. Lovett','J. Barthram','T. Plavotic','J.
Munns','L. Davis','K. Wootton','J. Dayton']
As I will be repeating this process many hundreds of times with different data (same structure) I was wondering if anyone could give me some tips on automatically building these ranges?
Thanks,
Peter
I'm not sure I understood what is the problem you are trying to solve but I'll try to help.
Assuming you have a dictionary team_dict and you want to create 2 list: hometeamPositions and hometeamPlayers you can use the following code:
hometeamPlayers = []
hometeamPositions = []
for player_dict in teams_dict['homeTeam']['lineupsSorted']:
hometeamPlayers.append(player_dict['player']['shortName'])
hometeamPositions.append(player_dict['positionName'])
The output on your example will be:
hometeamPlayers = ['S. P. Brown', 'C. Winchester']
hometeamPositions = ['Goalkeeper', 'Midfielder']

Query Elasticsearch by id using the regex or wildcard filter

I got a list of IDs:
bc2***********************13
b53***********************92
39f***********************bb
eb7***********************7a
80b***********************22
Each * is a unknown char and I need to find all IDs matching these patterns.
I tried the regex filter on field names like id, _id and ID, always with "bc2.*13" (or others) but always got no matches even for existing documents.
By default, _id field is not indexed : that's why you have no results.
Try setting _id field as analyzed in the mapping:
POST /test_id/
{
"mappings":{
"indexed":{
"_id":{
"index":"analyzed"
}
}
}
}
Adding some docs :
PUT /test_id/indexed/bc2***********************13
{
"content":"test1"
}
PUT /test_id/indexed/b53***********************92
{
"content":"test2"
}
I checked with one of your simple regexp query :
POST /test_id/_search
{
"query": {
"regexp": {
"_id": "bc2.*13"
}
}
}
Result :
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "test_id",
"_type": "indexed",
"_id": "bc2***********************13",
"_score": 1,
"_source": {
"content": "test1"
}
}
]
}
Hope this helps :)
If the *'s are of a known and constant length:
bc2.{23}13|b53.{23}92|39f.{23}bb|eb7.{23}7a|80b.{23}22
DEMO
Else:
bc2.*?13|b53.*?92|39f.*?bb|eb7.*?7a|80b.*?22
DEMO2
Use the _uid field and the wildcard query:
GET yourIndex/yourType/_search
{
"query": {
"wildcard": {
"_uid": "bc2***********************13"
}
}
}