GithubHelp home page GithubHelp logo

swiftype-node's Introduction

Elastic Site Search Logo

⚠️ This repository is deprecated ⚠️

Please visit https://github.com/elastic/site-search-node for the up to date version. Thank you! - Elastic

GitHub release

A first-party Node client for the Elastic Site Search API.

Contents


Getting started 🐣

With npm:

npm install swiftype

or clone locally:

$ git clone [email protected]:swiftype/swiftype-node.git
$ cd swiftype-node
$ npm install

Usage

Create a new instance of the client with your api key:

var SwiftypeApi = require('swiftype')
var swiftype = new SwiftypeApi({
  apiKey: 'yourApiKey'
})

Searching

Search for cats on the engine my-engine with filters and facets:

swiftype.search({
  engine: 'my-engine',
  q: 'cats',
  filters: {
    page: {
      'enumField': 'theFilter'
    }
  },
  facets: {
    page: ['enumField', 'anotherField']
  }
}, function(err, res) {
  console.log(res)
})

Autocomplete

Autocomplete suggestion for cat on the engine my-engine with filters:

swiftype.suggest({
  engine: 'my-engine',
  q: 'cat',
  filters: {
    page: {
      'enumField': 'theFilter'
    }
  }
}, function(err, res) {
  console.log(res)
})

Click

Log clickthrough for cat on the engine my-engine for the documentType page:

swiftype.click({
  engine: 'my-engine',
  q: 'cat',
  id: 'the-document-id',
  documentType: 'page'
}, function(err, res) {
  console.log(res)
})

Documents

Create a new document:

swiftype.documents.create({
  engine: 'my-engine',
  documentType: 'books',
  document: {
    external_id: '1',
    fields: [
      { name: 'title', value: 'The Great Gatsby', type: 'string' },
      { name: 'author', value: 'F. Scott Fitzgerald', type: 'string' },
      { name: 'genre', value: 'fiction', type: 'enum' }
    ]
  }
}, function(err, res) {
  console.log(res)
})

Engines

Fetch all of your engines:

swiftype.engines.list(function(err, res) {
  console.log(res)
})

Fetch a single engine:

swiftype.engines.get({
  engine: 'my-engine'
}, function(err, res) {
  console.log(res)
})

Document Types

Fetch all of the document types in the engine my-engine

swiftype.documentTypes.list({
  engine: 'my-engine'
}, function(err, res) {
  console.log(res)
})

Fetch the document type books in the engine my-engine

swiftype.documentTypes.get({
  engine: 'my-engine',
  documentType: 'books'
}, function(err, res) {
  console.log(res)
})

Create the document type books in the engine my-engine

swiftype.documentTypes.create({
  engine: 'my-engine',
  document_type: { name: 'books' }
}, function(err, res) {
  console.log(res)
})

Check out the tests for more examples!

Running tests

$ npm test

The tests use stubbed HTTP interactions that are recorded with the node-replay module. By default, HTTP interactions are not allowed when running the tests.

The tests can also use environment variables so that you can create new replays against your own account. Don't forget to change the "authorization" header in the replay files to not give away your api key.

  • SWIFTYPE_TEST_MY_ENGINE = the slug for your 'my-engine' in the tests
  • SWIFTYPE_TEST_BOOKSTORE_ENGINE = the slug for your 'bookstore' in the tests
  • SWIFTYPE_TEST_TEMPORARY_ENGINE = the slug for your 'temporary' in the tests
  • SWIFTYPE_TEST_API_KEY = your api key in the tests
  • REPLAY = 'record' to record new replay files

FAQ 🔮

Where do I report issues with the client?

If something is not working as expected, please open an issue.

Where can I learn more about Site Search?

Your best bet is to read the documentation.

Where else can I go to get help?

You can checkout the Elastic Site Search community discuss forums.

Contribute 🚀

We welcome contributors to the project. Before you begin, a couple notes...

License 📗

MIT © Elastic

Thank you to all the contributors!

swiftype-node's People

Contributors

damienwhaley avatar goodroot avatar jasonstoltz avatar jonasll avatar look avatar mikesea avatar orhantoy avatar qhoxie avatar trek avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.