We're almost there! 
This is the result of the query that I have posted: 

   - hits: {
      - total: 3
      - max_score: 4.724929
      - hits: [
         - {
            - _index: website
            - _type: structure
            - _id: 7
            - _score: 4.724929
            - fields: {
               - bologna_count: 0
            }
         }
         - {
            - _index: website
            - _type: structure
            - _id: 8
            - _score: 4.724929
            - fields: {
               - bologna_count: 0
            }
         }
         - {
            - _index: website
            - _type: structure
            - _id: 6
            - _score: 4.724929
            - fields: {
               - bologna_count: 0
            }
         }
      ]
   }


in fact located all three records that contain "bologna" in the "locality" 
and "region", but bologna_count is always 0 and replicates the result 3 
times. 
For example: 
the three records they found as locality: 
"bologna" 
"bologna" 
"Bolognano" 

What I would like is that I give back as a result: (similar to this)
hits: [
   
   - {
      - _index: website
      - _type: structure
      - _score: 4.724929
      - fields: {
         - count: 2
         locality:"bologna"
      }
   }
   - {
      - _index: website
      - _type: structure
      - _score: 4.724929
      - fields: {
         - count: 1
         locality:"bolognano"
      }
   }
   ]



so that it knows that there are 2 records with the name "bologna" and 1 as 
"bolognano."

Thanks


Il giorno venerdì 14 febbraio 2014 13:42:14 UTC+1, Binh Ly ha scritto:
>
> I'm still not 100% sure I understand. Is this something that might work?
>
> {
>   "query": {
>     "multi_match": {
>       "query": "bologna",
>       "fields": [
>         "locality",
>         "region"
>       ]
>     }
>   },
>   "script_fields": {
>     "bologna_count": {
>       "script": "_index['locality']['bologna'].tf() + _index['region']['
> bologna'].tf()"
>     }
>   }
> }
>

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elasticsearch+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/24d41fdb-2faf-4380-97c2-f0d56d4f0f20%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to