Elastic search setup task - noorzaman/emp GitHub Wiki

Elastic Search Instance

An elastic search instance has been added at:
https://search-emp-cixk22lczi5yrt4zd2dhswnltm.us-east-1.es.amazonaws.com/

For testing on your machine:

Simple Curl Based Tests

In these simple tests, we will:

  • create an index (think of a db table) called food and
  • add several restaurants with different ethnicities
  • each entry can be given an id or elastic search will automatically do it for us
curl -X DELETE "$addr/food"
curl -X PUT "$addr/food"
curl -X GET "$addr/food"?pretty

curl -X POST "$addr/food/id1" -H'Content-Type: application/json' -d '{"restaurant":"indian", "flavor":"spicy"}'

curl -X GET "$addr/food/_search?q=*&pretty"

Inserting Sample Meeting Spaces

Casual Meeting Space

Also checked in as: harard_square_starbucks.json

curl -X POST "$addr/emp/rooms/casual" -H'Content-Type: application/json' -d '
{
  "meeting_place": {
    "email":"[email protected]",
    "name":"Starbucks coffee at Harvard",
    "theme":"casual", 
    "capacity":"unlimited",
    "description":"Starbucks coffee at Harvard square",
    "create_date":"20180304",
    "update_date":"20180304"
  },
  "location": {
    "office_space":"false",
    "office":{
      "room_name":"",
      "floor":"",
      "building":""
    },
    "other": {
      "business_name":"Petes",
      "street_address":"2780 Mowry Ave",
      "city": "Fremont",
      "zip_code":"94538",
      "state":"CA"
    }
  },
  "tags":[
    "wifi",
    "coffee",
    "breakfast",
    "snacks"
  ]
}'

Professional Meeting Space

curl -X POST "$addr/emp/rooms/professional" -H'Content-Type: application/json' -d '
{
  "meeting_place": {
    "email":"[email protected]",
    "name":"Big conference room",
    "theme":"professional", 
    "capacity":"25",
    "description":"The big room at Pfizer main building",
    "create_date":"20180304",
    "update_date":"20180304"
  },
  "location": {
    "office_space":"true",
    "office":{
      "room_name":"godzilla",
      "floor":"3",
      "building":"Pfizer Building 1"
    },
    "other": {
      "business_name":"",
      "street_address":"",
      "city": "",
      "zip_code":"",
      "state":""
    }
  },
  "tags":[
    "television",
    "projector",
    "speakerphone",
    "whiteboard"
  ]
}'

Searching Sample Meeting Spaces

To find all rooms:

curl -X GET "$addr/emp/rooms/_search?q=*&pretty"

To find a room by an attribute (or theme):

curl -X GET "$addr/emp/rooms/_search?q=meeting_place.theme:casual&pretty"

Check the mapping structure

curl -X GET "$addr/emp/rooms/_mapping"?pretty

{"emp":{"mappings":{"rooms":{"properties":{"location":{"properties":{"office":{"properties":{"building":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"floor":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"room_name":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}},"office_space":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"other":{"properties":{"business_name":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"city":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"state":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"street_address":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"zip_code":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}}}},"meeting_place":{"properties":{"capacity":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"create_date":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"description":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"email":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"name":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"theme":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"update_date":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}},"tags":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}}}}}

Adding an _all index

curl -X PUT "$addr/emp?" -H'Content-Type: application/json' -d '{"mapping":{"rooms":{"_all":{"enabled":true}}}}'
Setting up a suggestions index

https://search-emp-cixk22lczi5yrt4zd2dhswnltm.us-east-1.es.amazonaws.com/


curl -XPUT "$addr/sugg1?pretty" -H 'Content-Type: application/json' -d'
{
    "mappings": {
        "doc" : {
            "properties" : {
                "suggest" : {
                    "type" : "completion"
                },
                "title" : {
                    "type": "keyword"
                }
            }
        }
    }
}
'




curl -XPUT "$addr/sugg1/doc/1?refresh&pretty" -H 'Content-Type: application/json' -d'
{
    "suggest" : {
        "input": [ "Nevermind", "Nirvana" ],
        "weight" : 34
    }
}
'


curl -XPUT "$addr/sugg1/doc/2?refresh&pretty" -H 'Content-Type: application/json' -d'
{
    "suggest" : [
        {
            "input": "Nevermind",
            "weight" : 10
        },
        {
            "input": "Nirvana",
            "weight" : 3
        }
    ]
}
'


curl -XPUT "$addr/sugg1/doc/3?refresh&pretty" -H 'Content-Type: application/json' -d'
{
  "suggest" : [ "Neverland", "Nonetheless" ]
}
'



curl -XPOST "$addr/sugg1/_search?pretty&pretty" -H 'Content-Type: application/json' -d'
{
    "suggest": {
        "song-suggest" : {
            "prefix" : "nir", 
            "completion" : { 
                "field" : "suggest"
            }
        }
    }
}
'

Add visual tags:

curl -X DELETE "$addr/emptags" curl -X PUT "$addr/emptags"

curl -X POST "$addr/emptags/vtags/starbucks" -H'Content-Type: application/json' -d ' { "name": "Starbucks", "themes": [ "casual", "zen" ], "tags": [ "coffee", "mocha", "https://www.starbucks.com" ], "data": "https://s3.amazonaws.com/empstorage/bfd4e3fa-0055-4588-a700-f8a6658f5e2e" }'

curl -X POST "$addr/emptags/vtags/chipotle" -H'Content-Type: application/json' -d ' "name": "Chipotle", "themes": [ "casual", "zen" ], "tags": [ "burrito", "salad", "https://www.chipotle.com" ], "data": "https://s3.amazonaws.com/empstorage/bfd4e3fa-0055-4588-a700-f8a6658f5e2e" }'

curl -X GET "$addr/emptags/_search"?pretty

curl -X GET "$addr/emptags/vtags/_search"?pretty

curl -X GET https://search-emp-cixk22lczi5yrt4zd2dhswnltm.us-east-1.es.amazonaws.com/emp/rooms/_search?pretty -H 'Content-Type: application/json' -d' { "size": 0, "aggs": { "attributes": { "terms": { "field": "space.attributes.keyword", "size": 50000 } } } }'

curl -X POST "$addr/tags/fixed/tags_list" -H 'Content-Type: application/json' -d '
{
"space": {
"added_ts": "20180304",
"name": "Fixed Tags",
"image_key": "[email protected]",
"image": "null",
"updated_ts": "20180304",
"attributes": [
"Whiteboard", 
"TV",
"Projector",
"Board Room",
"Restaurant",
"Cafe",
"Table",
"Chair",
"Couch",
"Desk",
"Chalkboard",
"Phone",
"Speakers",
"Outlets",
"Smartboard",
"Microphone",
"Lecturn",
"Auditorium",
"Classroom",
"Boardroom",
"Theater",
"Kitchenette",
"Hallway",
"Lounge",
"Bar",
"Indoor",
"Outdoor"
],
"capacity": 0,
"themes": "FixedTags",
"description": "Fixed common use tags for meeting spaces"
}
}'

⚠️ **GitHub.com Fallback** ⚠️