2012-06-30 5 views
0

여러 필드에 대해 text_phrase 쿼리를 어떻게 사용할 수 있습니까?여러 필드에 대한 텍스트 쿼리

내 경우 :
사용자 유형 hello world. 제목 또는 내용 (또는 둘 모두) 필드에 hello (cool) world ->이 문서를 반환하십시오.

답변

4

이렇게하려면 boost 쿼리를 사용하십시오. text 쿼리의보다 진보 된 형식을 사용하여 제목을 높이기를 원할 수도 있습니다 (때로는 필드의 길이가 점수에 영향을주는 제목 문서의 표준을 비활성화하는 것이 좋습니다). 다음은 전체 샘플입니다.

curl -XPUT localhost:9200/test -d '{ 
    "index.number_of_shards" : 1, 
    "index.number_of_replicas" : 0 
}' 

curl -XPUT localhost:9200/test/type/1 -d '{ 
    "title" : "hello (cool) world", 
    "content" : "hello (cool) world" 
}' 

curl -XPUT localhost:9200/test/type/2 -d '{ 
    "title" : "hello (cool) world", 
    "content" : "xxx" 
}' 

curl -XPUT localhost:9200/test/type/3 -d '{ 
    "title" : "yyy", 
    "content" : "hello (cool) world" 
}' 

curl -XPOST localhost:9200/test/_refresh 

curl -XGET localhost:9200/test/_search?pretty -d '{ 
    "query" : { 
     "bool" : { 
      "should" : [ 
       { 
        "text" : {"content" : {"query" : "hello world"}} 
       }, 
       { 
        "text" : {"title" : {"query" : "hello world", "boost" : 5}} 
       } 
      ] 
     } 
    } 
}' 
관련 문제