GithubHelp home page GithubHelp logo

vineeth-mohan / elasticsearch-payload-scoring-function Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 2.0 164 KB

Elasticsearch plugin for payload function scoring plugin for function_score query

Java 100.00%

elasticsearch-payload-scoring-function's Introduction

Elasticsearch Payload score based function Plugin

Payload function plugin for function score query in Elasticsearch

The payload value is taken from termVectors if enabled ( This is faster ) or from the reverse index.

Versions

Elasticsearch Plugin Release date
1.7.0 1.7.0.0 Sept 7, 2015

Sample usecase

Sample documentA
( A lot of gravy and very spicy )

	{
	  "name": "chilli chicken",
	  "tasteTypes": [
	    "spicy|100",
	    "salty|10",
	    "gravy|100"
	  ]
	}

Sample documentB

( Lot of gravy gravy bu not very spicy )

	{
	  "name": "Chicken with nuts",
	  "tasteTypes": [
	    "spicy|20",
	    "sweet",
	    "gravy|100"
	  ]
	}

Here as you can see the level of spicy and gravy is different for different dishes. So when i search for dishes which are spicy , it makes sense to show "chilli chicken" above "chicken with nuts" as the former is more spicy.

In such cases , using the plugin i made , we can give search as follows -

	{
	  "query": {
	    "function_score": {
	      "query": {
	        "term": "spicy"
	      },
	      "functions": [
	        {
	          "payload_factor": {
	            "tasteTypes": [
	              "spicy"
	            ]
	          }
	        }
	      ]
	    }
	  }
	}

The result will have documentA as the highest score.

Installation

mvn clean install -DskipTests

The distribution would be present in target/releases

unzip and copy the zip file in there to the plugin folder

Do not forget to restart the node after installing.

To install using plugin

./bin/plugin -install payload-scoring -url  http://factweavers.com/repository/com/factweavers/elasticsearch/plugin/elasticsearch-payload-scoring-function/1.7.0.0/elasticsearch-payload-scoring-function-1.7.0.0-plugin.zip

Issues

All feedback is welcome! If you find issues, please post them at Github

Example

curl -XDELETE 'localhost:9200/test'

curl -XPUT 'localhost:9200/test' -d '{
  "settings" : {
     "number_of_shards" : "1",
     "number_of_replicas" : "0",
     "analysis" : {
	    "analyzer" : {
	        "my_payload_analyzer" : {
	            "tokenizer" : "whitespace",
	            "filter" : [ "delimited_payload_filter" ]
	        }
	     }
     }
  }
}'
echo
curl -XPUT 'localhost:9200/test/docs/_mapping' -d '{
      "properties" : {
	"content" : {
	  "type": "string",
	  "analyzer" : "my_payload_analyzer",
	  "term_vector": "with_positions_offsets_payloads"
	}
      }
}'
echo
curl -XPUT 'localhost:9200/test/docs/1' -d '{
    "content" : "foo bar baz|3.0"
}'
echo

curl -XPUT 'localhost:9200/test/docs/2' -d '{
    "content" : "foo bar|2.0 baz"
}'
echo
sleep 2
curl -XPOST 'http://localhost:9200/test/_search' -d '{
  "explain": true,
  "query": {
    "function_score": {
      "query": {
	"match_all": {}
      },
      "score_mode": "sum",
      "boost_mode": "replace",
      "functions": [
	{
	  "payload_factor": {
	    "field": "content",
	    "values": [
	      "bar",
	      "baz"
	    ]
	  }
	}
      ]
    }
  }
}'

License

Elasticsearch Payload scoring function Plugin

Copyright (C) 2015 Vineeth Mohan

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. you may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

elasticsearch-payload-scoring-function's People

Contributors

vineeth-mohan avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

elasticsearch-payload-scoring-function's Issues

payload_factor query does not support [field name][term]];

Query itself : { "query": { "function_score": { "query": { "match_all":{} }, "functions": [ { "payload_factor": { "docInfo": [ "test" ] } } ] } } }
settings for index are like this :
{ "settings" : { "number_of_shards" : "1", "number_of_replicas" : "0", "analysis" : { "analyzer" : { "my_payload_analyzer" : { "tokenizer" : "whitespace", "filter" : [ "delimited_payload_filter" ] } } } } }
field is defined like this :
"docInfo": { "analyzer" : "my_payload_analyzer", "term_vector": "with_positions_offsets_payloads", "type": "string" }
and in a single document inserted it looks like this : "docInfo":"test|20 document|10"
Will attach logs later. Great plugnin any way.

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.