WordPress powers more than 35% of all websites on the internet (according to Kingsta.com), and if your company has a showcase website or a blog, you probably use wordpress. 

With a simple plugin, you can enhance your wordpress search by using Elasticsearch. 

TL:DR

Increase your ROI and the sessions durations on your website in less than an hour of work. 

  • Provide typo tolerant case insensitive search
  • Search result by score
  • Suggest similar articles
  • Filter results in one click with facets
  • Search into document content (pdf, word, etc…)

WordPress is a free easy to install Content Management System to create web sites. 

As it’s the market leader and open source, a lot of plugins exist to enhance default behaviour. 

And of course a plugin to use the open source leader of search also exists. 

Search for a content website

Classical search can be enough for most simple use cases. 

But as your post quantity is growing, it will become harder and harder for your visitors to find the right content. 

Usually, 70% of your users come from your long trail. It means that those visitors will land into your website for a very precise thing, and probably in a deep page of your site. 

For thoses users (but not only), retention is hard.
A good search engine will help you keep visitors on your website as long as possible. 

Why Elasticsearch for my wordpress site

The goal of Elasticsearch is to improve user experience.
In your wordpress it will mean a lot!

With Elasticsearch capabilities, you will able to:

  • Speed up a lot the search responses
  • Give better search results, easier (typo tolerance, case insensitive, etc…)
  • Help visitors finding interesting internal content that fit their personals interests with similar articles
  • Filter content easily by category or tags
  • Search in word or PDF document content

And there’s more!

All that points are key for a good SEO onsite optimisation. 

  • Response time enhance your google rating
  • Search pages create specific pages with huge keyword density
  • Similar articles suggestion also boost the keyword density in your page
Suggested similar content in wordpress
Suggested articles on spoon-elastic.com

Elastic Press

Elastic press logo

A benefit of using wordpress is that there is a plugin for that!

Elastic Press is the best plugin to use wordpress with Elasticsearch. 

It has a good rating and is well maintained .

Usually, there is only a few weeks before the last version of the plugin is compatible with the last version of Elasticsearch.

The benefits of using Elastic Press : 

Easy Administration

  • Plugged in wp_query, so all your search queries will automatically use Elasticseach
  • No need to understand ES for easiest uses cases. For more a minimum understanding is enough
  • Manage synchronization between wordpress and elastic, and manage mappings
  • Compatible with Woo commerce
  • Provide an admin interface to manage weight of each field (known as boost in the elasticsearch world)
Elasticsearch Boost management
Boost field weight

Front end integration : 

  • Automatically plugged on your standard wordpress search form
  • Similar articles widget
  • Facets widgets

You can test this by doing a search on this website and by looking around this blog post 😉

Elasticsearch used by Elasticpress : 

By default, Elastic Press index content in your self elasticsearch. It also provides and hosts versions of elasticsearch for their clients. 

The index mapping is quite interesting. 

But for more advanced users, the usage of elastic search can be improved, depending on your use cases. 

At first, indices are created the old fashioned way, with 5 primary shards. 
If you don’t have billions of posts, I guess that 1 or 2 shards are far enough.
Avoid Oversharding! 

Some field definition choices are done to cover the larger use cases, but for a lot of them you could minimize the ignore_above size and change some data types from long to integer or short.

Want to know more ?

In this talk you will understand how to use Elasticsearch in your website as a developer thanks to ElasticPress.

Find the whole project code in Github : https://github.com/10up/ElasticPress

Elasticsearch index Mapping for advanced users: 

Default index settings and mapping

When you first index your documents, it will create an index like this :
Websitename–website-post-1.

For the spoon-elastic website the index definition looks like this: 

{
  "spoonelastic--spoonelasticcom-post-1" : {
    "aliases" : { },
    "mappings" : {
      "dynamic_templates" : [
        {
          "template_meta" : {
            "path_match" : "post_meta.*",
            "mapping" : {
              "fields" : {
                "{name}" : {
                  "type" : "text"
                },
                "raw" : {
                  "ignore_above" : 10922,
                  "type" : "keyword"
                }
              },
              "path" : "full",
              "type" : "text"
            }
          }
        },
        {
          "template_meta_types" : {
            "path_match" : "meta.*",
            "mapping" : {
              "path" : "full",
              "properties" : {
                "date" : {
                  "format" : "yyyy-MM-dd",
                  "type" : "date"
                },
                "datetime" : {
                  "format" : "yyyy-MM-dd HH:mm:ss",
                  "type" : "date"
                },
                "boolean" : {
                  "type" : "boolean"
                },
                "double" : {
                  "type" : "double"
                },
                "raw" : {
                  "ignore_above" : 10922,
                  "type" : "keyword"
                },
                "time" : {
                  "format" : "HH:mm:ss",
                  "type" : "date"
                },
                "value" : {
                  "type" : "text",
                  "fields" : {
                    "raw" : {
                      "ignore_above" : 10922,
                      "type" : "keyword"
                    },
                    "sortable" : {
                      "normalizer" : "lowerasciinormalizer",
                      "ignore_above" : 10922,
                      "type" : "keyword"
                    }
                  }
                },
                "long" : {
                  "type" : "long"
                }
              },
              "type" : "object"
            }
          }
        },
        {
          "template_terms" : {
            "path_match" : "terms.*",
            "mapping" : {
              "path" : "full",
              "properties" : {
                "parent" : {
                  "type" : "long"
                },
                "name" : {
                  "type" : "text",
                  "fields" : {
                    "raw" : {
                      "type" : "keyword"
                    },
                    "sortable" : {
                      "normalizer" : "lowerasciinormalizer",
                      "type" : "keyword"
                    }
                  }
                },
                "term_taxonomy_id" : {
                  "type" : "long"
                },
                "term_order" : {
                  "type" : "long"
                },
                "term_id" : {
                  "type" : "long"
                },
                "slug" : {
                  "type" : "keyword"
                }
              },
              "type" : "object"
            }
          }
        },
        {
          "term_suggest" : {
            "path_match" : "term_suggest_*",
            "mapping" : {
              "analyzer" : "default",
              "type" : "completion"
            }
          }
        }
      ],
      "date_detection" : false,
      "properties" : {
        "ID" : {
          "type" : "long"
        },
        "comment_count" : {
          "type" : "long"
        },
        "comment_status" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "date_terms" : {
          "properties" : {
            "day" : {
              "type" : "integer"
            },
            "dayofweek" : {
              "type" : "integer"
            },
            "dayofweek_iso" : {
              "type" : "integer"
            },
            "dayofyear" : {
              "type" : "integer"
            },
            "hour" : {
              "type" : "integer"
            },
            "m" : {
              "type" : "integer"
            },
            "minute" : {
              "type" : "integer"
            },
            "month" : {
              "type" : "integer"
            },
            "second" : {
              "type" : "integer"
            },
            "week" : {
              "type" : "integer"
            },
            "year" : {
              "type" : "integer"
            }
          }
        },
        "guid" : {
          "type" : "keyword"
        },
        "menu_order" : {
          "type" : "long"
        },
        "meta" : {
          "properties" : {
            "page_footer" : {
              "properties" : {
                "boolean" : {
                  "type" : "boolean"
                },
                "date" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd"
                },
                "datetime" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd HH:mm:ss"
                },
                "double" : {
                  "type" : "double"
                },
                "long" : {
                  "type" : "long"
                },
                "raw" : {
                  "type" : "keyword",
                  "ignore_above" : 10922
                },
                "time" : {
                  "type" : "date",
                  "format" : "HH:mm:ss"
                },
                "value" : {
                  "type" : "text",
                  "fields" : {
                    "raw" : {
                      "type" : "keyword",
                      "ignore_above" : 10922
                    },
                    "sortable" : {
                      "type" : "keyword",
                      "ignore_above" : 10922,
                      "normalizer" : "lowerasciinormalizer"
                    }
                  }
                }
              }
            },
            "page_header" : {
              "properties" : {
                "boolean" : {
                  "type" : "boolean"
                },
                "date" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd"
                },
                "datetime" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd HH:mm:ss"
                },
                "double" : {
                  "type" : "double"
                },
                "long" : {
                  "type" : "long"
                },
                "raw" : {
                  "type" : "keyword",
                  "ignore_above" : 10922
                },
                "time" : {
                  "type" : "date",
                  "format" : "HH:mm:ss"
                },
                "value" : {
                  "type" : "text",
                  "fields" : {
                    "raw" : {
                      "type" : "keyword",
                      "ignore_above" : 10922
                    },
                    "sortable" : {
                      "type" : "keyword",
                      "ignore_above" : 10922,
                      "normalizer" : "lowerasciinormalizer"
                    }
                  }
                }
              }
            },
            "page_title" : {
              "properties" : {
                "boolean" : {
                  "type" : "boolean"
                },
                "date" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd"
                },
                "datetime" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd HH:mm:ss"
                },
                "double" : {
                  "type" : "double"
                },
                "long" : {
                  "type" : "long"
                },
                "raw" : {
                  "type" : "keyword",
                  "ignore_above" : 10922
                },
                "time" : {
                  "type" : "date",
                  "format" : "HH:mm:ss"
                },
                "value" : {
                  "type" : "text",
                  "fields" : {
                    "raw" : {
                      "type" : "keyword",
                      "ignore_above" : 10922
                    },
                    "sortable" : {
                      "type" : "keyword",
                      "ignore_above" : 10922,
                      "normalizer" : "lowerasciinormalizer"
                    }
                  }
                }
              }
            },
            "service_featured" : {
              "properties" : {
                "boolean" : {
                  "type" : "boolean"
                },
                "date" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd"
                },
                "datetime" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd HH:mm:ss"
                },
                "double" : {
                  "type" : "double"
                },
                "long" : {
                  "type" : "long"
                },
                "raw" : {
                  "type" : "keyword",
                  "ignore_above" : 10922
                },
                "time" : {
                  "type" : "date",
                  "format" : "HH:mm:ss"
                },
                "value" : {
                  "type" : "text",
                  "fields" : {
                    "raw" : {
                      "type" : "keyword",
                      "ignore_above" : 10922
                    },
                    "sortable" : {
                      "type" : "keyword",
                      "ignore_above" : 10922,
                      "normalizer" : "lowerasciinormalizer"
                    }
                  }
                }
              }
            },
            "service_icon" : {
              "properties" : {
                "boolean" : {
                  "type" : "boolean"
                },
                "date" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd"
                },
                "datetime" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd HH:mm:ss"
                },
                "double" : {
                  "type" : "double"
                },
                "long" : {
                  "type" : "long"
                },
                "raw" : {
                  "type" : "keyword",
                  "ignore_above" : 10922
                },
                "time" : {
                  "type" : "date",
                  "format" : "HH:mm:ss"
                },
                "value" : {
                  "type" : "text",
                  "fields" : {
                    "raw" : {
                      "type" : "keyword",
                      "ignore_above" : 10922
                    },
                    "sortable" : {
                      "type" : "keyword",
                      "ignore_above" : 10922,
                      "normalizer" : "lowerasciinormalizer"
                    }
                  }
                }
              }
            },
            "service_layout" : {
              "properties" : {
                "boolean" : {
                  "type" : "boolean"
                },
                "date" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd"
                },
                "datetime" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd HH:mm:ss"
                },
                "double" : {
                  "type" : "double"
                },
                "long" : {
                  "type" : "long"
                },
                "raw" : {
                  "type" : "keyword",
                  "ignore_above" : 10922
                },
                "time" : {
                  "type" : "date",
                  "format" : "HH:mm:ss"
                },
                "value" : {
                  "type" : "text",
                  "fields" : {
                    "raw" : {
                      "type" : "keyword",
                      "ignore_above" : 10922
                    },
                    "sortable" : {
                      "type" : "keyword",
                      "ignore_above" : 10922,
                      "normalizer" : "lowerasciinormalizer"
                    }
                  }
                }
              }
            },
            "team_description" : {
              "properties" : {
                "boolean" : {
                  "type" : "boolean"
                },
                "date" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd"
                },
                "datetime" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd HH:mm:ss"
                },
                "double" : {
                  "type" : "double"
                },
                "long" : {
                  "type" : "long"
                },
                "raw" : {
                  "type" : "keyword",
                  "ignore_above" : 10922
                },
                "time" : {
                  "type" : "date",
                  "format" : "HH:mm:ss"
                },
                "value" : {
                  "type" : "text",
                  "fields" : {
                    "raw" : {
                      "type" : "keyword",
                      "ignore_above" : 10922
                    },
                    "sortable" : {
                      "type" : "keyword",
                      "ignore_above" : 10922,
                      "normalizer" : "lowerasciinormalizer"
                    }
                  }
                }
              }
            },
            "team_featured" : {
              "properties" : {
                "boolean" : {
                  "type" : "boolean"
                },
                "date" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd"
                },
                "datetime" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd HH:mm:ss"
                },
                "double" : {
                  "type" : "double"
                },
                "long" : {
                  "type" : "long"
                },
                "raw" : {
                  "type" : "keyword",
                  "ignore_above" : 10922
                },
                "time" : {
                  "type" : "date",
                  "format" : "HH:mm:ss"
                },
                "value" : {
                  "type" : "text",
                  "fields" : {
                    "raw" : {
                      "type" : "keyword",
                      "ignore_above" : 10922
                    },
                    "sortable" : {
                      "type" : "keyword",
                      "ignore_above" : 10922,
                      "normalizer" : "lowerasciinormalizer"
                    }
                  }
                }
              }
            },
            "team_links" : {
              "properties" : {
                "boolean" : {
                  "type" : "boolean"
                },
                "date" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd"
                },
                "datetime" : {
                  "type" : "date",
                  "format" : "yyyy-MM-dd HH:mm:ss"
                },
                "double" : {
                  "type" : "double"
                },
                "long" : {
                  "type" : "long"
                },
                "raw" : {
                  "type" : "keyword",
                  "ignore_above" : 10922
                },
                "time" : {
                  "type" : "date",
                  "format" : "HH:mm:ss"
                },
                "value" : {
                  "type" : "text",
                  "fields" : {
                    "raw" : {
                      "type" : "keyword",
                      "ignore_above" : 10922
                    },
                    "sortable" : {
                      "type" : "keyword",
                      "ignore_above" : 10922,
                      "normalizer" : "lowerasciinormalizer"
                    }
                  }
                }
              }
            }
          }
        },
        "permalink" : {
          "type" : "keyword"
        },
        "ping_status" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "post_author" : {
          "properties" : {
            "display_name" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" : "keyword"
                },
                "sortable" : {
                  "type" : "keyword",
                  "normalizer" : "lowerasciinormalizer"
                }
              }
            },
            "id" : {
              "type" : "long"
            },
            "login" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" : "keyword"
                },
                "sortable" : {
                  "type" : "keyword",
                  "normalizer" : "lowerasciinormalizer"
                }
              }
            },
            "raw" : {
              "type" : "keyword"
            }
          }
        },
        "post_content" : {
          "type" : "text"
        },
        "post_content_filtered" : {
          "type" : "text"
        },
        "post_date" : {
          "type" : "date",
          "format" : "yyyy-MM-dd HH:mm:ss"
        },
        "post_date_gmt" : {
          "type" : "date",
          "format" : "yyyy-MM-dd HH:mm:ss"
        },
        "post_excerpt" : {
          "type" : "text"
        },
        "post_id" : {
          "type" : "long"
        },
        "post_meta" : {
          "type" : "object"
        },
        "post_mime_type" : {
          "type" : "keyword"
        },
        "post_modified" : {
          "type" : "date",
          "format" : "yyyy-MM-dd HH:mm:ss"
        },
        "post_modified_gmt" : {
          "type" : "date",
          "format" : "yyyy-MM-dd HH:mm:ss"
        },
        "post_name" : {
          "type" : "text",
          "fields" : {
            "post_name" : {
              "type" : "text"
            },
            "raw" : {
              "type" : "keyword",
              "ignore_above" : 10922
            }
          }
        },
        "post_parent" : {
          "type" : "long"
        },
        "post_status" : {
          "type" : "keyword"
        },
        "post_title" : {
          "type" : "text",
          "fields" : {
            "post_title" : {
              "type" : "text",
              "analyzer" : "standard"
            },
            "raw" : {
              "type" : "keyword",
              "ignore_above" : 10922
            },
            "sortable" : {
              "type" : "keyword",
              "ignore_above" : 10922,
              "normalizer" : "lowerasciinormalizer"
            }
          }
        },
        "post_type" : {
          "type" : "text",
          "fields" : {
            "post_type" : {
              "type" : "text"
            },
            "raw" : {
              "type" : "keyword"
            }
          }
        },
        "terms" : {
          "properties" : {
            "category" : {
              "properties" : {
                "name" : {
                  "type" : "text",
                  "fields" : {
                    "raw" : {
                      "type" : "keyword"
                    },
                    "sortable" : {
                      "type" : "keyword",
                      "normalizer" : "lowerasciinormalizer"
                    }
                  }
                },
                "parent" : {
                  "type" : "long"
                },
                "slug" : {
                  "type" : "keyword"
                },
                "term_id" : {
                  "type" : "long"
                },
                "term_order" : {
                  "type" : "long"
                },
                "term_taxonomy_id" : {
                  "type" : "long"
                }
              }
            },
            "post_tag" : {
              "properties" : {
                "name" : {
                  "type" : "text",
                  "fields" : {
                    "raw" : {
                      "type" : "keyword"
                    },
                    "sortable" : {
                      "type" : "keyword",
                      "normalizer" : "lowerasciinormalizer"
                    }
                  }
                },
                "parent" : {
                  "type" : "long"
                },
                "slug" : {
                  "type" : "keyword"
                },
                "term_id" : {
                  "type" : "long"
                },
                "term_order" : {
                  "type" : "long"
                },
                "term_taxonomy_id" : {
                  "type" : "long"
                }
              }
            }
          }
        }
      }
    },
    "settings" : {
      "index" : {
        "mapping" : {
          "total_fields" : {
            "limit" : "5000"
          },
          "ignore_malformed" : "true"
        },
        "number_of_shards" : "5",
        "provided_name" : "spoonelastic--spoonelasticcom-post-1",
        "max_shingle_diff" : "8",
        "max_result_window" : "1000000",
        "creation_date" : "1587706382501",
        "analysis" : {
          "filter" : {
            "shingle_filter" : {
              "max_shingle_size" : "5",
              "min_shingle_size" : "2",
              "type" : "shingle"
            },
            "edge_ngram" : {
              "min_gram" : "3",
              "side" : "front",
              "type" : "edgeNGram",
              "max_gram" : "10"
            },
            "ewp_word_delimiter" : {
              "type" : "word_delimiter",
              "preserve_original" : "true"
            },
            "ewp_snowball" : {
              "type" : "snowball",
              "language" : "english"
            }
          },
          "normalizer" : {
            "lowerasciinormalizer" : {
              "filter" : [
                "lowercase",
                "asciifolding"
              ],
              "type" : "custom"
            }
          },
          "analyzer" : {
            "ewp_lowercase" : {
              "filter" : [
                "lowercase"
              ],
              "type" : "custom",
              "tokenizer" : "keyword"
            },
            "shingle_analyzer" : {
              "filter" : [
                "lowercase",
                "shingle_filter"
              ],
              "type" : "custom",
              "tokenizer" : "standard"
            },
            "default" : {
              "filter" : [
                "ewp_word_delimiter",
                "lowercase",
                "stop",
                "ewp_snowball"
              ],
              "char_filter" : [
                "html_strip"
              ],
              "language" : "english",
              "tokenizer" : "standard"
            }
          }
        },
        "number_of_replicas" : "1",
        "uuid" : "nMv3Z_LmT7iLRRF1W7rQJg",
        "version" : {
          "created" : "7060099"
        }
      }
    }
  }
}


Spoon consulting is a certified partner of Elastic

As a certified partner of the Elastic company, Spoon Consulting offers a high level consulting for all kinds of companies, ranging from small and medium companies to large multinationals.

More than 90% of our clients use Multi-cloud today. Besides, many of them use more than one public cloud provider. In this context, more than ever what is the most important is : data quality, adoption of cloud and integrity with the SI.

Read more information on your personal use Elasticsearch use case on Spoon consulting’s posts

Or contact Spoon consulting now.