2013-03-18 4 views
0

나는 도서 제목 목록을 가지고 있으며, 색인에 해당 도서가 있는지 알고 싶습니다.elasticsearch에있는 목록의 일부를 검색하십시오.

매핑은 다음과 같습니다

"book": { 
    "properties": { 
        "title":{"type":"string"}, 
        "author":{"type":"string"}}} 

내가 반복하고 확인

curl -XPOST 'localhost:9200/myindex/book/_search' 
-d '{"query":{"match":{"title":"my title"}}} 

하지만 난 긴 제목의 목록을 가정하고 각 하나를 내가 대량으로이 작업을 수행 할 수있는 방법 및 목록을 얻을 수 어떤 사람들이 명중 했습니까? 제목 필드에 대한

답변

0

실행 여러 match 쿼리하는 bool 쿼리를 결합 : 물론

curl -XGET 'http://127.0.0.1:9200/myindex/book/_search?pretty=1' -d ' 
{ 
    "query" : { 
     "bool" : { 
     "should" : [ 
      { 
       "match" : { 
        "title" : "Title one" 
       } 
      }, 
      { 
       "match" : { 
        "title" : "Title two" 
       } 
      }, 
      { 
       "match" : { 
        "title" : "Title three" 
       } 
      } 
     ] 
     } 
    } 
} 
' 

하는 match 쿼리가 그 title 필드 쿼리 문자열에서 한 단어가 포함 된 모든 책에 일치합니다, 그래서 대신 match_phrase을 사용할 수 있습니다 :

curl -XGET 'http://127.0.0.1:9200/myindex/book/_search?pretty=1' -d ' 
{ 
    "query" : { 
     "bool" : { 
     "should" : [ 
      { 
       "match_phrase" : { 
        "title" : "Title one" 
       } 
      }, 
      { 
       "match_phrase" : { 
        "title" : "Title two" 
       } 
      }, 
      { 
       "match_phrase" : { 
        "title" : "Title three" 
       } 
      } 
     ] 
     } 
    } 
} 
' 

이 정확한 구문을 검색합니다 같은 순서로 같은 단어.

관련 문제