Skip to content

Instantly share code, notes, and snippets.

@hkulekci
Created May 2, 2019 12:43
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/dd61b9b2e89dc3329e0d77b57fe0f3d7 to your computer and use it in GitHub Desktop.
Save hkulekci/dd61b9b2e89dc3329e0d77b57fe0f3d7 to your computer and use it in GitHub Desktop.
Esalticsearch Example Usage
DELETE demodata


PUT demodata
{
  "mappings": {
    "document": {
      "properties": {
        "documentName": {
          "type": "keyword",
          "fields": {
            "text": {
              "type": "text"
            }
          }
        }
      }
    }
  }
}

POST demodata/document
{
  "id": "1",
  "documentName": "document.txt"
}

POST demodata/document
{
  "id": "2",
  "documentName": "documend.txt"
}

POST demodata/document
{
  "id": "3",
  "documentName": "documen.txt"
}
POST demodata/document
{
  "id": "4",
  "documentName": "documenptxt"
}
POST demodata/document
{
  "id": "5",
  "documentName": "document1.txt"
}

POST demodata/document
{
  "id": "6",
  "documentName": "document0.txt"
}

GET demodata/_search

GET demodata/_search
{
  "query": {
    "regexp": {
      "documentName": "document.*"
    }
  }
}

GET demodata/_search
{
  "query": {
    "regexp": {
      "documentName": "document.txt"
    }
  }
}

GET demodata/_search
{
  "query": {
    "regexp": {
      "documentName": "document1.txt"
    }
  }
}

GET demodata/_search
{
  "query": {
    "regexp": {
      "documentName": "document[1-9]*.txt"
    }
  }
}


GET demodata/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "regexp": {
            "documentName": "document[1-9]*.txt"
          }
        },
        {
          "prefix": {
            "documentName.text": {
              "value": "document"
            }
          }
        }
      ],
      "minimum_should_match": 1
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment