Skip to content

Instantly share code, notes, and snippets.

View mattfield11's full-sized avatar

Matt Field mattfield11

View GitHub Profile
@mattfield11
mattfield11 / gist:2136a5a7c91ba7d20889562232df0db7
Created November 13, 2023 13:55
Analyzer for SKUs in Elasticsearch
## Analyzer for SKUs
The analyzer below will strip out any of the items defined in the regex. In this case i am removing -#_ and any whitespace.
You can adapt the regex as appropriate. In this case the search WILL be case sensitive.
As a keyword tokenizer is used, then the text will not be split into "words" .
```
PUT my-index-000001
{
@mattfield11
mattfield11 / product_recommender.query
Last active September 1, 2017 10:45
elasticsearch product recommendation
POST user_purchases/_search?
{
"size": 0,
"query": {
"bool": {
"filter": [
{ "term": { "product_id.raw": "polaroid x1566" }}
]
PUT user_purchases
{
"mappings": {
"user_history": {
"properties": {
"user_id":{
"type": "text",
"fields": {
"raw": {
@mattfield11
mattfield11 / wikipeople.suggester
Created August 30, 2017 12:37
ELASTICSEARCH AUTO COMPLETE SUGGESTER SAMPLE QUERY AND RESPONSE
POST wikipeople/_search?pretty
{
"_source": {
"excludes": [ "text" ]
},
"suggest": {
"people-suggest" : {
"prefix" : "ada",
"completion" : {
GET wikipeople/_search
{
"_source": {
"excludes": [ "text" ]
},
"query": {
"bool": {
"should": [
{ "match": {
PUT wikipeople
{
"mappings": {
"wiki_page": {
"properties": {
"text": {
"type": "text",
"fields": {
"english": {
"type": "text",
@mattfield11
mattfield11 / wikipeopleloader.py
Last active August 30, 2017 11:23
Pywikibot to elasticsearch
import pywikibot
from pywikibot import pagegenerators
from elasticsearch import Elasticsearch
import json
es = Elasticsearch()
data = {}
site = pywikibot.Site()
cat = pywikibot.Category(site,'Category:Living people')