1

please show me the right direction :)

I've a task: find documents in elastic search by query, which may contain unnecessary words.

I'll show what I mean:

assume that I have some document which contains words "big red car" (now they are in different fields in index), and I want to find this document with a queries like: "big dark red car" or "very big light red muscule car" or even "the big car has beatiful red color". But, in same time I want to save opportunity to find by "red car" or "big car"

List of unnecessary words undefined and I can't add them to stop-words.

Thank you in advance (:

1 Answers1

0

Elasticsearch has a bool query type. You can add define your query with it. I won't give you an exact code. Since its look like a homework or an assignment. If you provide us what you have done so far, then i might add a working code.

But here is the pseudocode:

carQuery = fieldName with fieldValue 'car'
bigQuery = fieldName with fieldValue 'big'
redQuery = fieldName with fieldValue 'red'

boolQuery.must(carQuery).should(bigQuery).mustnot(redQuery)

I hope it will be useful.

shyos
  • 1,390
  • 1
  • 16
  • 29
  • yes, it seems that it works for me if I put all fields to a some other field **text**, then JSON for request will be this: { "query": { "bool": { "should": [ {"term": { "text": { "term": "big"}}}, {"term": { "text": { "term": "red"}}}, {"term": { "text": { "term": "car"}}} ] } } } – Sergey Lobin Nov 22 '13 at 19:52