Skip to content

Instantly share code, notes, and snippets.

@hkulekci
Last active October 23, 2018 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkulekci/672e5e1c8d0359dfdb549290734267ad to your computer and use it in GitHub Desktop.
Save hkulekci/672e5e1c8d0359dfdb549290734267ad to your computer and use it in GitHub Desktop.
Medium Example


DELETE cities

PUT cities
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0,
    "analysis": {
      "analyzer": {
        "default_search": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "standard",
            "lowercase",
            "mySnowball",
            "asciifolding"
          ]
        }
      },
      "filter": {
        "mySnowball": {
          "type": "snowball",
          "language": "Turkish"
        }
      }
    }
  }
}


PUT cities/city/_mapping
{
  "properties": {
    "id": {
      "type": "integer"
    },
    "parent": {
      "type": "integer"
    },
    "name": {
      "type": "text"
    },
    "parentOne": {
      "type": "text"
    },
    "parentTwo": {
      "type": "text"
    },
    "placeSearch": {
      "type": "completion",
      "analyzer": "default_search",
      "search_analyzer": "default_search"
    }
  }
}


POST cities/city/39344
{
  "id": 39344,
  "parent": 39342,
  "name": "Yenidoğan Mah.",
  "parentOne": "Numunebağ",
  "parentTwo": "Bayrampaşa",
  "placeSearch": {
    "input": ["Yenidoğan Mah.", "Numunebağ", "Bayrampaşa"]
  },
  "point": {
    "lat": 41.058014,
    "lon": 28.913599
  }
}

POST cities/city/39382
{
  "id": 39382,
  "parent": 39349,
  "name": "Maçka",
  "parentOne": "Beşiktaş",
  "parentTwo": "Beşiktaş",
  "placeSearch": {
    "input": ["Maçka", "Beşiktaş", "Beşiktaş"]
  }
}


POST cities/city/39348
{
  "id": 39348,
  "parent": 39345,
  "name": "Yıldırım Mah.",
  "parentOne": "Yıldırım",
  "parentTwo": "Bayrampaşa",
  "placeSearch": {
    "input": ["Yıldırım Mah.", "Yıldırım", "Bayrampaşa"]
  },
  "point": {
    "lat": 41.0635811,
    "lon": 28.891878
  }
}

POST cities/city/39346
{
  "id": 39346,
  "locationType": 64,
  "parent": 39345,
  "name": "Enverbey",
  "parentOne": "Şişhane",
  "parentTwo": "Beyoğlu",
  "placeSearch": {
    "input": ["Enverbey", "Şişhane", "Beyoğlu"]
  },
  "point": {
    "lat": 41.0635811,
    "lon": 28.891878
  }
}

POST cities/city/39347
{
  "id": 39347,
  "parent": 39345,
  "name": "Şişli",
  "parentOne": "Şişli",
  "parentTwo": "Mecidiyeköy",
  "placeSearch": {
    "input": ["Şişli", "Mecidiyeköy"]
  },
  "point": {
    "lat": 41.0635811,
    "lon": 28.891878
  }
}

Search :

GET cities/_search
{
  "suggest": {
    "suggest": {
      "completion": {
        "field": "placeSearch",
        "size": 7
      },
      "text": "Sis"
    }
  }
}

Result :

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": 0,
    "hits": []
  },
  "suggest": {
    "suggest": [
      {
        "text": "Sis",
        "offset": 0,
        "length": 3,
        "options": [
          {
            "text": "Şişhane",
            "_index": "cities",
            "_type": "city",
            "_id": "39346",
            "_score": 1,
            "_source": {
              "id": 39346,
              "locationType": 64,
              "parent": 39345,
              "name": "Şishane",
              "parentOne": "Şişhane",
              "parentTwo": "Macunköy",
              "placeSearch": {
                "input": [
                  "Şişhane",
                  "Macunköy"
                ]
              },
              "point": {
                "lat": 41.0635811,
                "lon": 28.891878
              }
            }
          },
          {
            "text": "Şişli",
            "_index": "cities",
            "_type": "city",
            "_id": "39347",
            "_score": 1,
            "_source": {
              "id": 39347,
              "parent": 39345,
              "name": "Şişli",
              "parentOne": "Şişli",
              "parentTwo": "Mecidiyeköy",
              "placeSearch": {
                "input": [
                  "Şişli",
                  "Mecidiyeköy"
                ]
              },
              "point": {
                "lat": 41.0635811,
                "lon": 28.891878
              }
            }
          }
        ]
      }
    ]
  }
}

POST cities/city/39347
{
  "id": 39347,
  "parent": 39345,
  "name": "Şişli",
  "parentOne": "Şişli",
  "parentTwo": "Mecidiyeköy",
  "placeSearch": [
    {
      "input": ["Şişli"],
      "weight": 3
    },
    {
      "input": ["Mecidiyeköy"],
      "weight": 2
    }
  ],
  "point": {
    "lat": 41.0635811,
    "lon": 28.891878
  }
}

POST cities/city/39344
{
  "id": 39344,
  "parent": 39345,
  "name": "Enverbey",
  "parentOne": "Şişhane",
  "parentTwo": "Beyoğlu",
  "placeSearch": [
    {
      "input": ["Enverbey"],
      "weight": 3
    },
    {
      "input": ["Sishane"],
      "weight": 2
    },
    {
      "input": ["Beyoğlu"],
      "weight": 1
    }
  ],
  "point": {
    "lat": 41.0635811,
    "lon": 28.891878
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment