title: Elasticsearch Array Comparison
body: <p>I'm new to elasticsearch, so be kind.</p>
  
  <p>I'm trying to store and query data, which is tagged with N number of tags.  I want to compare a search query array with the stored array and return the results in order of which items match the most tags.</p>
  
  <p>Dataset example:</p>
  
  <pre><code>{ name: "karl", tags: ["terrible", "programmer"] }
  { name: "bob", tags: ["awesome", "programmer"] }
  </code></pre>
  
  <p>Query example, matching both people:</p>
  
  <pre><code>query: { tags: ["programmer"] }
  result: [karl, bob]
  </code></pre>
  
  <p>And in this example, both are returned but bob scores high, because more tags were matched, <strong>Karl is still shown though</strong>, despite not matching on <code>awesome</code>.</p>
  
  <pre><code>query: { tags: ["programmer", "awesome"] }
  result: [bob, karl]
  </code></pre>
  
  <p>The closet I have got is this, however it doesn't seem to score bob higher than karl</p>
  
  <pre><code>{
    "query": {
      "bool": {
        "should": [
          { "match": { "tags": "programmer" } },
          { "match": { "tags": "awesome" } }
         ],
        "minimum_number_should_match": 1
      }
    }
  }
  </code></pre>
  
  <p>Would love some support :-)
  Thanks!</p>